r/C_Homework • u/danieleldr3d • Feb 24 '17
Caeser Cipher Help!
I'm tasked with creating a cipher using one function. It must read in a string of no more than 80 characters and a number. The cipher must be applied to every lower case character in the string.
Here's what I've got so far:
include <stdio.h>
int main() { char str1[80]; int cipher; int i; char c;
printf("Enter any message of no more than 80 characters: \n");
fgets(str1, 80, stdin);
printf("How many shifts of the alphabet would you like to take place?\n"); scanf("%i", &cipher);
for(i=0; str1[i]!='\0'; i++) { if((str1[i] > 96) && (str1[i] < 123)) (str1[i] + cipher); }
c=((str1[i]-97+cipher)%26)+97;
printf("%s\n", c);
return 0; }
View all comments
Show parent comment
1
u/danieleldr3d Feb 28 '17
Yeah sorry about that.. first time posting on reddit. No it doesn't work. It's really frustrating!! It works when I input between like 0 and 12 'turns' of the cipher wheel. I've only been programming since last October so I'm not exactly experienced in C, and this is probably the most stuck I've ever been on a task!