From 2f5609430f4174c32180975bf86c1b79eba0d0c9 Mon Sep 17 00:00:00 2001 From: Cian Bagshaw Date: Sun, 4 Dec 2022 12:42:31 +0000 Subject: [PATCH] Added exercise 1-6 --- 1/6.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 1/6.c diff --git a/1/6.c b/1/6.c new file mode 100644 index 0000000..e1e40c1 --- /dev/null +++ b/1/6.c @@ -0,0 +1,17 @@ +/* + Exercise 1-6. Verify that the expression getchar() != EOF is 0 or 1. + === + + Each character typed returned a 1, until I typed Ctrl+d, to signify the end of + input, which yielded a 0. Therefor, getchar()!=EOF is 1 with all characters and + 0 a the end of input/file. Thus, it always equals 0 or 1. +*/ + +#include + +int main () { + int c; + while ((c=getchar())!=EOF) { + printf("%d ", c!=EOF); /* while input */ + } printf("%d ", c!=EOF); /* on input end */ +} -- 2.20.1