Exercise #1.5.3 - Line Counting

alendr · updated September 15, 2021 · C
#include <stdio.h>
/* Count lines in input */ 
int main() {
    int c, nl; 
    nl = 0; 
    while ((c = getchar()) != EOF) 
        if (c == '\n') 
            ++nl; 
    printf("%d\n", nl); 
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.