I'm a total newb to C. I bought C: The Programming Language to start learning, but I have a question about a couple examples, one to count characters, the other to count lines. They're not printing anything, and I'm not sure why. I've double and triple checked everything, making sure I have exactly what's in the book, but to no avail. I'm using Code Blocks 8.02 and Vista.
Code:
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%1d\n", nc);
}
The second example, the second version, doesn't work either.
Code:
#include <stdio.h>
/* count characters in input; 2nd version */
main()
{
double nc;
for (nc = 0; getchar() != EOF; ++nc)
;
print("%.0f\n", nc);
}
The third is the line counting one
Code:
#include <stdio.h>
/* count lines in input */
main()
{
int c, n1;
n1 = 0;
while ((c = getchar()) != EOF)
if (c == '\n')
++n1;
printf("%d\n", n1);
}
Any help is appreciated, of course. Thanks.