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
1
u/dmc_2930 Feb 24 '17
A few notes.
In C, you have to use assignment if you want to change a value.
a+4; /* Does nothing / a=7; / Assigns 7 to a */
Based on those two examples, how might you add something to 'a'?