From 6bf093f44f3aeaa6ec25bbe7d08be454727d7a43 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Tue, 9 Nov 2021 00:36:42 -0500 Subject: [PATCH] Line counting example --- 06-line-count.c | 12 ++++++++++++ Makefile | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 06-line-count.c diff --git a/06-line-count.c b/06-line-count.c new file mode 100644 index 0000000..f7338b5 --- /dev/null +++ b/06-line-count.c @@ -0,0 +1,12 @@ +#include + +int main() +{ + int c, n1; + + n1 = 0; + while ((c = getchar ()) != EOF) + if (c == '\n') + ++n1; + printf("%d\n", n1); +} diff --git a/Makefile b/Makefile index e60db29..7e067df 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: hello mathvars c2f input count +all: hello mathvars c2f input count countlines hello: 01-hello-world.c gcc -o ./bin/01-helloworld 01-hello-world.c @@ -15,5 +15,8 @@ input: 04-file-copying.c count: 05-char-counting.c gcc -o ./bin/05-count 05-char-counting.c +countlines: 06-line-count.c + gcc -o ./bin/06-line-count 06-line-count.c + clean: $(RM) ./bin/*-*