Counts input lines from user input - C Data Type

C examples for Data Type:char

Description

Counts input lines from user input

Demo Code

#include <stdio.h>  
  
   int main(){  /*from   w ww  . j av  a  2 s .  co m*/
       int c, nl = 0;  
  
       while ((c = getchar()) != EOF)  {
           if (c == '\n')  
               ++nl;  
               }
       printf("%d\n", nl);  

   }

Result


Related Tutorials