Thursday, July 9, 2009

Problem with EOF in C probably simple but i a noob C programmer?

#include%26lt;stdio.h%26gt;





/* count characters in input; 1st version */





main()


{


long nc;





nc = 0;


while (getchar() != EOF)


++nc;


printf("%ld\n",nc);


}








here is just some simple code that doesnt run properly, it compiles fine. i will run it, input the value as "asdfas" and i hit enter and it never terminates.

Problem with EOF in C probably simple but i a noob C programmer?
Enter is the character '\n' and not EOF.


No comments:

Post a Comment