R
randomtalk
hello, recently i am reading "The C Programming Language, Second
Edition", and for some reason, the sample program in there doesn't work
as expected under GCC.. here is the code:
#include <stdio.h>
/* count lines in input */
main()
{
int c, nl;
nl = 0;
while ((c = getchar()) != EOF)
if (c == '\n')
++nl;
printf("%d\n", nl);
}
which should get all the input, count the lines, and return some
number.. However, when i ran it, it just looped input over and over, it
doesn't ever see the EOF for some reason.. So i type in something, hit
enter, it just gives me the input box again, without counting
anything.. anyone know what's wrong?
Edition", and for some reason, the sample program in there doesn't work
as expected under GCC.. here is the code:
#include <stdio.h>
/* count lines in input */
main()
{
int c, nl;
nl = 0;
while ((c = getchar()) != EOF)
if (c == '\n')
++nl;
printf("%d\n", nl);
}
which should get all the input, count the lines, and return some
number.. However, when i ran it, it just looped input over and over, it
doesn't ever see the EOF for some reason.. So i type in something, hit
enter, it just gives me the input box again, without counting
anything.. anyone know what's wrong?