I'm learning the C Programming Language, and I'm using the book "The C Programming Language, Second Edition" by Kernighan and Ritchie.
I was using Miracle C for my compiler and everything was working okay, until i got to the Line Counting Program they had there:
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);
}
It makes perfect sense to me and it should work, but instead, when you type something and press enter, it just moves onto the next line for you to type-- the line count variable (nl) is never printed to the output.
I thought it might be the compiler... I tried it with compiler "Dev-C++" (its both a C++ and C compiler) and got the same problem. Is it a problem with the code? Is this book flawed?
Thanks.