Counting lines doesn't work

I am new to programming and am following a book about C++ programming. When I type the following code and click "Debug" I get a black screen and nothing happens. There is a printf function so I assume something is supposed to happen. Please help.

#include <stdio.h>

int main()
{

int c, nl;

nl = 0;
while ((c = getchar()) != EOF) {
if (c == '\n')
++nl;
}
printf("%d\n",nl);

return 0;
}
The code works fine.
Output:
Line 1
Line 2
Line 3
^Z
3

Did you actually enter sth. ?

BTW. Are you sure that the book is about C++, the code is pure C.
You are supposed to type multiple lines of text and press Ctrl+Z when you're done.
Thank you for the help. Still there is a problem. When I click Ctrl+Z, the program exits out. If i add #include <conio.h> and a _getch(); at the end, then the programs runs fine, why is that?
Some IDE's (like Visual Studio) have this behaviour to close the console at the end of main.
Thank you!
Topic archived. No new replies allowed.