#include #define MAXLINE 1024 /* * read a line into s, return length, * assume length is less than MAXLINE * and the line number is less than MAXLINE */ int get_line(char s[], int lim) { int c, i; for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i) { s[i] = c; } if (c == '\n') { /* increment i after assignment */ s[i++] = c; } /* put null character at end of string */ s[i] = '\0'; return i; } /* copy from into to */ void copy(char to[], char from[]) { int i = 0; /* '\0' marks end of string */ while ((to[i] = from[i]) != '\0') { ++i; } } /* remove trailing whitespace */ void trim(char s[], int i) { /* skip null character and new line */ i -= 2; while (i >= 0 && (s[i] == ' ' || s[i] == '\t')) { --i; } s[i] = '\0'; } /* flip characters in string */ void reverse(char s[]) { int i = 0; while (s[i] != '\n') { ++i; } --i; char c; for (int j = 0; j < i / 2; ++j) { c = s[i - j]; s[i - j] = s[j]; s[j] = c; } } /* print longest input line */ int main() { char line[MAXLINE], longest[MAXLINE]; int len; int max = 0; while ((len = get_line(line, MAXLINE)) > 0) { if (len > max) { max = len; copy(longest, line); } } if (max > 0) { /* trim(longest, max); */ /* reverse(longest); */ printf("%s", longest); } return 0; }