diff options
author | Adam Carpenter <gitlab@53hor.net> | 2019-07-09 16:00:48 -0400 |
---|---|---|
committer | Adam Carpenter <gitlab@53hor.net> | 2019-07-09 16:00:48 -0400 |
commit | 39c0cbcc70aff47e17107826aa76cb525c83b122 (patch) | |
tree | df483af220a11aab49e0e3a76eea54f60efbd424 /ch1/line_counter.c | |
parent | 583fc81152e120ec5873f8057f11a894bb8b0a91 (diff) | |
download | learning-c-39c0cbcc70aff47e17107826aa76cb525c83b122.tar.xz learning-c-39c0cbcc70aff47e17107826aa76cb525c83b122.zip |
ch2
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); +} |