I've been reading "The C Programming Language" and I got to this part of inputs and outputs.
I've read other threads saying that the console doesn't recognize enter as EOF
. So that I should use CTRL + Z in Windows or CTRL + D in Unix (neither of those is working for me).
I also read other people asking the same saying they could make it work, the problem in their codes was syntax not the program not terminating.
Is there another solution?
This is the code:
#include <stdio.h>
main()
{
int nb, nl, nt, c;
nb = 0;
nl = 0;
nt = 0;
while ((c = getchar()) != '
'){
if (c == ' ')
++nb;
else if (c == '
')
++nl;
else if (c == '')
++nt;
}
printf("Input has %d blanks, %d tabs, and %d newlines
", nb, nt, nl);
}
Edit: The
was supposed to be an EOF, I was messing around before I posted and I forgot I changed it :P
It doesn't work with EOF neither, I just skipped that one.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…