I have been learning C from K&Re2. And the above code is what is mentioned in Pg18(Letter counting program), which I ran for confirmation purposes. I tried entering few characters and press ENTER
, but it was not working. Then I heard about CTRL+Z
,CTRL+C
or CTRL+D
with ENTER
for End Of File. I tried it in NetBeans console, but it was not working. I tried
and
too, pity it was not working too. I have searched for this, but all seemed to have solved the problem with CTRL+Z
,CTRL+C
or CTRL+D
with ENTER
method. I can't understand what is the problem here.
PS: I use Windows 7
Sorry for not inserting code directly. Here is it-
#include <stdio.h>
#include <stdlib.h>
int main() {
long c = 0;
while (getchar() != EOF) {
++c;
}
printf("%ld", c);
return 0;
}
In the image, I have not initialized value of long c
. Sorry for that. This program is running, but the methods I use for EOF doesn't work out.
EDIT:
I have tried compiling in NetBeans, and then running the resulting .exe in cmd rather than in NetBeans console. CTRL+Z
seems to work! Do you guys have any idea why it doesn't work in NetBeans console?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…