About Rot13-Implementation

c, rot13

Solution

Thanks a lot guys, I solved the problem with this code

#include <stdio.h>

int rot13(int c){
  if('a' <= c && c <= 'z'){
    return rot13b(c,'a');
  } else if ('A' <= c && c <= 'Z') {
    return rot13b(c, 'A');
  } else {
    return c;
  }
}

int rot13b(int c, int basis){
  c = (((c-basis)+13)%26)+basis;
  return c;
}

int main() {
  printf("The given args will be rotated");
  int c;
  while((c = getchar()) != EOF){
    c = rot13(c);
    putchar(c);
  }
  return 0;
}

Problem

I am trying to implement the rot13-algorithm in C. But since I am not very familiar with that language, I have some problems with my code right here. Basically, I want to rotate every letter in args[] to 13 positions up. But this code seems to be pretty sluggish: ``` #include <stdio.h> char[] rotate(char c[]) { char single; int i; int alen = sizeof(c)/sizeof(c[0]); char out[alen]; for(i=0;i<=alen;i+=1) { if(c[i]>='a' && (c[i]+13)<='z'){ out[i] = c[i]+13; } } return out; } int main(int argc, char *argv[]) { printf("The given args will be rotated\n"); int i; char rotated[sizeof(argv)/sizeof(argv[0])]; rotated = rotate(argv); /* printing rotated[] later on */ return 0; } ``` I know there a lot of holes here - could you show me how to fix this?

Original source