From c24973af02bc33f2f5f25d37e22ca91da5de3c47 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 4 Jun 2022 12:11:15 +0530 Subject: inital commit --- 1.16.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 1.16.c (limited to '1.16.c') diff --git a/1.16.c b/1.16.c new file mode 100644 index 0000000..12c9600 --- /dev/null +++ b/1.16.c @@ -0,0 +1,52 @@ +#include + +#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; + 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; +} + +void +cp_str(char to[], char from[]) +{ + for(int i =0; (to[i] = from[i]) != '\0'; i++) + ; +} -- cgit v1.2.3