how to exit this loop

I am trying to count number of lines. How do I stop this loop to print the number of lines.
Professor told me to try ctrl+d. I tried but doesn't work.

1
2
3
4
5
6
7
8
9
10
11
#include<stdio.h> 
 
 main( ) 
{
      int c,n;
      n = 0;
      while( (c=getchar( )) != '\0' )
             if( c == '\n' )
                      ++n;
      printf("%d lines\n", n);
       }
getchar() will never return 0, not even when the user presses CTRL+D. Try while >=0, or !=EOF.
number of lines of what?
Topic archived. No new replies allowed.