[ad_1]
When I compile and run code from http://www.learntosolveit.com/cprogramming/rot13.html and have a file alpha
as
a
b
c
cat alpha | ./a.out
gives
n
o
p
However, I wrote a code doing the same rotation as
#include <stdio.h>
int main()
{
char ch;
ch = getchar();
if ('a' <= ch && ch <= 'm'){
putchar(ch+13);}
else if ('A' <= ch && ch <= 'M'){
putchar(ch+13);}
else if ('n' <= ch && ch <= 'z'){
putchar(ch-13);}
else if ('N' <= ch && ch <= 'Z'){
putchar(ch-13);}
return(0);
}
then cat alpha | ./a.out
gives
nop
I thought in order to add newline, we also have to put putchar(‘\n’). Why is the behavior different? Thanks
[ad_2]