aboutsummaryrefslogtreecommitdiff
path: root/2.2.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 /2.2.c
inital commit
Diffstat (limited to '2.2.c')
-rw-r--r--2.2.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/2.2.c b/2.2.c
new file mode 100644
index 0000000..4e3f71a
--- /dev/null
+++ b/2.2.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+
+#define MAXLINE 1000
+
+int gline(char str[], int len);
+void cp_str(char to[], char from[]);
+
+int
+main(void)
+{
+ int len, max;
+ char str[MAXLINE];
+ char mstr[MAXLINE];
+
+ max = 0;
+
+ while ((len = gline(str, MAXLINE)) > 0)
+ if (len > max) {
+ cp_str(mstr, str);
+ max = len;
+ }
+
+ if (max > 0)
+ printf("\nlength: %d\n%s", max, mstr);
+
+ return 0;
+}
+
+int
+gline(char str[], int len)
+{
+ int i;
+ char input;
+
+ i = 0;
+
+ while (i < len-1) {
+ input = getchar();
+
+ if (input == EOF)
+ break;
+ else if (input == '\n')
+ break;
+
+ str[i] = input;
+ i++;
+ }
+
+
+ if (input == '\n' && i < len-1) {
+ str[i] = '\n';
+ ++i;
+ }
+
+ str[i] = '\0';
+
+ return i;
+}
+
+void
+cp_str(char to[], char from[])
+{
+ for(int i =0; (to[i] = from[i]) != '\0'; i++)
+ ;
+}