Hi everyone,
I'm writing code that uses an encoding called rot13, where each letter is shifted 13 spaces, so "a" becomes "n" and "b" becomes "o" etc. It was an old C assignment.
The problem:
When I enter Hello world, only hello is converted and not world.
Any ideas?
Code:/* Description: ROT13 encoding; to change each letter of a word 13 places along the alphabet. i.e, a becomes n. Input is from keyboard modified date:26/11/04 */ #include <stdio.h> //#include <CLIB.H> Commented out because it produces errors #include <string.h> main(){ char rot13[100]; int i=0; printf("Enter word n "); scanf("%s",rot13); for(i=0;i<(strlen(rot13));i++) { if (('a'<=rot13[i])&&(rot13[i]<='n')) { rot13[i]= rot13[i] + 13; } else if (('m'<=rot13[i])&&(rot13[i]<='z')) { rot13[i]= rot13[i] - 13; } else if (('A'<=rot13[i])&&(rot13[i]<='N')) { rot13[i]= rot13[i] + 13; } else if (('N'<=rot13[i])&&(rot13[i]<='Z')) { rot13[i]= rot13[i] - 13; } else if (rot13[i]== 32) // 32 is ACSII for space { rot13[i] = ' '; } } printf("%s\n",rot13); system("PAUSE"); // There is a better away to stop the program from quiting, not sure what it is }