#include <stdio.h>
#include <stdlib.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main( int argc,string argv[]){
int k;
if (argc == 2) {
k = atoi(argv[1]);
}
else
{
printf("Usage: ./caesar k");
}
string p = get_string();
printf("Plaintext: %s\n",p);
char c[100];
for(int i = 0,n = strlen(p);i < n;i++)
{
if(islower(p[i]) && isalpha(p[i]))
{
c[i] = (p[i] - 'a' + k) % 26 + 97;
}
if(isupper(p[i]) && isalpha(p[i]))
{
c[i] = (p[i] - 'A' + k) % 26 + 65;
}
{
printf("%c",c[i]);
}
}
}
}
printf("\n");
return 0;
}
In my printf statement where I want to print my Ciphertext, the printf function's output is behaving different to what I have anticapated.
CipherText:
for every character you encrypt. I would put it outside for loop (before for loop actually). – vadasambar Sep 26 '17 at 15:54