Hello everyone, i am in the beginning stages of creating my own caesar cipher and i am running into trouble with my cipher array.
If you run the program below and just input something simple like "my name is john doe" . "array" returns what it is supposed to, but "cipher" returns the encrypted message plus some other garbage as shown below:
"p|qdphlvu|dq�Rп���ȁ�Rп�".
What can i do to correct this?
here is the code:
Code:
#include <stdio.h>
#include <string.h>
#define MAX 100
main()
{
char array[MAX], cipher[MAX];
int i, x, c;
i = x = 0;
while((c=getchar()) != '\n')
{
array[i] = c;
cipher[x] = (int) c + 3;
x++;
i++;
}
printf("%s\n", array);
printf("%s\n", cipher);
}