I just started learning C and I ran into one problem.
I am using "The C Programming Language" from Brian Kernighan and Dennis Ritchie as a learning material so I am following the examples in that book.
The problem is with the following programme:
Now, it should give me, as a result, the number of lines in which I typed something. The problem is, when I press Ctrl+C, the programme ends without printing the last line of code.Code:#include <stdio.h> main() { int c, nl; nl = 0; while ((c=getchar()) !=EOF) if (c == '\n') ++nl; printf ("%d\n", nl); }
Exactly the same problem I encountered with character count.
The question is probably stupid, but as I said, I just started.
Any ideas?
P.S. I am using Geany as IDE. I tried compiling it outside of Geany, with
and then running it withCode:cc -c line.c cc -o line line.o
but no help.Code:./line



LinkBack URL
About LinkBacks



.