getchar () and EOF

#include<stdio.h>
#include<conio.h>

main()
{
int nc;
for (nc = 0; getchar() != EOF; ++nc)
;
printf("%d\n", nc);
getch();
}

i m not getting any output.
1
2
3
for (nc = 0; getchar() != EOF; ++nc)
;//your for loop only does this command (nothing)
printf("%d\n", nc); 

use braces instead or remove that pointless ;
1
2
3
for (nc = 0; getchar() != EOF; ++nc) {
printf("%d\n", nc); 
}
due to this for loop , nc is getting incremented..nd that is what to be done. and i dont want printf statement to come under for loop
... try Ctrl-Z.
Topic archived. No new replies allowed.