I have written this codefor (int i = 0 , n = strlen(alphabet); i < n ; i++)
, but only the first character has been verified.
I think I need another loop, so I have written this code for (int j = 0 ; j <= i; j++)
but it also not working.
I want to encrypt the input text, so I want the loop to be verified from all the letter in the words.
So this program encrypts just one letter.
I think to the problem from the loop for (int i = 0 , n = strlen(alphabet); i < n ; i++)
#include
include
include
include
include
int main(int argc, string argv[]) { if (argc < 0 ){ printf("usage: ./caesar key"); return 1; }
int k = atoi (argv[1]); string alphabet = get_string("plaintext: "); int c =0 , alph = 0 ; for (int i = 0 , n = strlen(alphabet); i < n ; i++) { alph = alphabet[i]; // for (int j = 0 ; j <= i; j++){ if (isalpha (alph)){ if (isupper (alph)){ alph = alph -'A'; c = (alph + k) % 26 ; alph = c + 'A' ; } else { alph = alphabet[i] - 'a' ; c = (alph + k) % 26 ; alph = c + 'a' ; } } printf("ciphertext: %c \n", alph); return 0; // } } }