/* prints the length of arbitrarily long input lines, and as much as * possible of the text. */ #include #define MAXLINE 1000 int getline(char s[], int lim) { int c, i, j; j = 0; for (i = 0; (c=getchar()) != EOF && c != '\n'; ++i) if (i < lim-2) { s[j] = c; j++; } if (c == '\n') { s[j] = c; j++; i++; } s[j] = '\0'; return i; } void copy(char s[], char t[]) { int i; for (i = 0; (s[i] = t[i]) != '\0'; i++); } int main(void) { int len, max; char line[MAXLINE]; char longest[MAXLINE]; max = 0; while((len = getline(line, MAXLINE)) > 0) { printf("%d, %s", len, line); if (len > max) { max = len; copy(longest, line); } } if (max > 0) printf("%s", longest); return 0; }