Added exercise 1-6
authorCian Bagshaw <cian@cianb.xyz>
Sun, 4 Dec 2022 12:42:31 +0000 (12:42 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Sun, 4 Dec 2022 12:42:31 +0000 (12:42 +0000)
1/6.c [new file with mode: 0644]

diff --git a/1/6.c b/1/6.c
new file mode 100644 (file)
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 <stdio.h>
+
+int main () {
+       int c;
+       while ((c=getchar())!=EOF) {
+               printf("%d ", c!=EOF);  /* while input */
+       }       printf("%d ", c!=EOF);  /* on input end */
+}