Could I get some help with my code? For some reason, the program ignores conditions and prints the wrong letter. For example, I would use the letter i as the key to convert Meet. It would come out as UmmX. If I use f, I would get Rjjy. The program only skips through the condition when it gets to the letter i and beyond. It would go through if(argv[1][j] > 96 && argv[1][j] < 123) for the first three letters and then skip to the else on the "t" even though it meets the if condition. I don't know why this is happening.
int main(int argc,string argv[])
{
if(argc !=2)
{
printf(" Need One More\n");
return 1;
}
int j = 0;
string plaintext = GetString();
int n = strlen(plaintext);
int m = strlen(argv[1]);
for(int i =0; i < n; i++)
{
if(isdigit(plaintext[i]) || plaintext[i] == 32 || plaintext[i] < 65 || (plaintext[i] > 90 && plaintext[i] < 97 )|| plaintext[i] > 122)
{
plaintext[i] = plaintext[i];
printf("%c", plaintext[i]);
}
if( j == m)
{
j = 0;
}
if(argv[1][j] > 96 && argv[1][j] < 123)
{
int leftover = argv[1][j] - 97;
if(plaintext[i] + leftover < 123)
{
plaintext[i] = plaintext[i] + leftover;
printf("%c", plaintext[i]);
j++;
}
else
{
plaintext[i] = 97+ (leftover + argv[1][j] - 122) ;
printf("%c", plaintext[i]);
j++;
}
}
else if(argv[1][j] < 91 && argv[1][j] > 64)
{
int leftover = argv[1][j] - 65;
if(plaintext[i] + leftover < 91)
{
plaintext[i] = plaintext[i] + leftover;
printf("%c", plaintext[i]);
j++;
}
else
{
plaintext[i] = 65+ (leftover + argv[1][j] - 65);
printf("%c", plaintext[i]);
j++;
}
}
}
printf("\n");