summaryrefslogtreecommitdiffstats
path: root/2/2.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-28 14:42:56 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-28 14:42:56 +0800
commitdc60b0b95c2026c9d295a4f04c329101425fe091 (patch)
tree13df93235f9604eafdfce8ca4afd155b7be29f0b /2/2.c
parent21b1681ea7c9693ddc41ec1478e4a336e4538818 (diff)
downloadk&r-exercises-dc60b0b95c2026c9d295a4f04c329101425fe091.tar.gz
2.2
Diffstat (limited to '2/2.c')
-rw-r--r--2/2.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/2/2.c b/2/2.c
new file mode 100644
index 0000000..f68d4b5
--- /dev/null
+++ b/2/2.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+#define MAXLEN 1000
+
+/* writes input to buffer without using && or || in loop */
+int main(int argc, char *argv[]) {
+ int i, c;
+ char s[MAXLEN];
+
+ for (i = 0; i < MAXLEN - 1; i++) {
+ if ((c = getchar()) == EOF) {
+ break;
+ }
+
+ if (c == '\n') {
+ break;
+ }
+
+ s[i] = c;
+ }
+
+ s[i] = 0;
+
+ return 0;
+} \ No newline at end of file