aboutsummaryrefslogtreecommitdiff
path: root/1.17.c
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
committersinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
commitc24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch)
tree460a005b6a3a9a967bd881bc2bf01e0becbe33cc /1.17.c
inital commit
Diffstat (limited to '1.17.c')
-rw-r--r--1.17.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/1.17.c b/1.17.c
new file mode 100644
index 0000000..5fca79c
--- /dev/null
+++ b/1.17.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+
+#define MAXLINE 1000
+
+int gline(char str[], int len);
+
+int
+main(void)
+{
+ int len;
+ char str[MAXLINE];
+
+ while ((len = gline(str, MAXLINE)) > 0)
+ if (len > 80)
+ printf("\nlength: %d\n%s\n", len, str);
+
+ return 0;
+}
+
+int
+gline(char str[], int len)
+{
+ int i;
+ char input;
+ for (i = 0; i < len-1 && (input = getchar()) != EOF && input != '\n'; i++)
+ str[i] = input;
+
+ if (input == '\n' && i < len-1) {
+ str[i] = '\n';
+ ++i;
+ }
+
+ str[i] = '\0';
+
+ return i;
+}