My result is wrong ! when I enter a word in plaintext, it just print 2 letters for infinity. Please help me understand how I can print ciphertext and the answer correctly please. Here is my code :
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
//select the second string which is the key
string key = argv[1];
//only 1 string is allowed next to the command
if (argc != 2)
{
printf("error\n");
return 1;
}
//convert the string to an integer
int k = atoi(key);
//key value should be positive
if (k > 0 )
{
//make plaintext input of user
{
printf("plaintext: ");
}
string plntxt = get_string();
if (plntxt != NULL)
{
printf("ciphertext: ");
}
//make plaintext encrypted
//use key input to encrypt
int c = 0;
for (int i = 0, n = strlen(plntxt); i < n; n++)
{
//make sure that string is letter
if (isalpha(plntxt[i]));
{
//preserve the lower case
if (islower(plntxt[i]));
{
// convert the asc II to alpha index
int p = plntxt [i] - 97;
//encrypted
c = (p + k) % 26;
// convert the encrypt to ascII
int letter = c + 97;
{
printf("%c", (char)letter);
}
}
//preserve the upper case
if (isupper(plntxt[i]));
{
// convert the asc II to alpha index
int p = plntxt [i] - 65;
//encrypted
c = (p + k) % 26;
// convert the encrypt to ascII
int nletter = c + 65;
{
printf("%c", (char)nletter);
}
}
printf("%c", (char)plntxt[i]);
}
}
}
{
printf("\n");
}
return 0;
}