Implementing a ROT13 program in C
I'm a complete beginner with C. I'm having trouble with the logic of
writing a ROT13 function. Here is the code I currently have:
void rot13(char *str)
{
int i;
for(i = 0; str[i] != '\0'; ++i) {
if(((str[i] >= 'A') && (str[i] < 'M')) || ((str[i] >= 'a') && (str[i]
< 'n'))) {
str[i] += 13;
}
if(((str[i] >= 'M') && (str[i] <= 'Z')) || ((str[i] >= 'm') && (str[i]
<= 'z'))) {
str[i] -= 13;
}
}
}
For some reason, it's not working with strings, but one letter works.
No comments:
Post a Comment