Ceaser program is meant to take your text , add the inputted key to it and display the cyphered text. My code adds 16 to whatever key i input.
I have hardcoded the code to subtract 16 from the key , it fixed all the issues but i have no idea what the real problem is.
CODE
#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(int argc, string argv[])
{`your text`
if(argc != 2)
{`your text`
printf("./ceaser (key here)n");
return 0;
}
else
{
// Make sure every character in argv[1] is a digit
int c = argv[1][0];
if(isdigit(c))
{
// Convert argv[1] from a `string` to an `int`
// int k = argv[1];
// Prompt user for plaintext
string p = get_string("Input text to be coded:");
int j = strlen(p);
for(int i = 0 ; i < j ; i++)
{
//p[i] = p[i] + c;
printf("%c" , p[i] + (c - 16));
}
}
else
{
printf("./ceaser (key here)n");
return 0;
}
}
}
`
New contributor
user26310611 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.