diff options
Diffstat (limited to 'ch1/line_counter.c')
-rw-r--r-- | ch1/line_counter.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ch1/line_counter.c b/ch1/line_counter.c new file mode 100644 index 0000000..0447aa7 --- /dev/null +++ b/ch1/line_counter.c @@ -0,0 +1,16 @@ +#include<stdio.h> + +/* + * Count lines in input + */ +main() { + int c, nl; + + nl = 0; + + while ((c = getchar()) != EOF) + if (c == '\n') + ++nl; + + printf("%d\n", nl); +} |