Here's my function and the problem is
It never stops getting the input, in the command line.
I can't figure out where is the proper line to place a return 0.
int my_rot13(int c) {
if ('a' <= tolower(c) && tolower(c) <= 'z')
return tolower(c)+13 <= 'z' ? c+13 : c-13;
return c;
}
int main() {
int k, c;
char *p;
if (argc < 2) {
while ((c = getc(stdin)) != EOF) {
putchar(my_rot13(c));
}
return 0;
}
for (k = 1; k < argc; k++) {
for (p = argv[k]; *p != '\0'; p++) {
putchar(my_rot13(*p));
}
putchar(' ');
}
putchar('\n');
return 0;
}
If I pass in the standard input like ./a.out "hey", it works exiting the program.
but when I get into user input mode I can not get out of this function.
(c = getc(stdin)) != '\n'to just accept one line. +1 for a well-formed question with proper codeEOF