#include #define MAXLINE 1000 /*max line length */ /* Demo of a program that finds out * the first line of maximal length in * a text file */ int getline (char s[], int lim); void copy (char s1[], char s2[]); /************/ main () { int len, max; char line[MAXLINE], save[MAXLINE]; printf ("Hello! This is an output of the program maxline.c\n"); max = 0; while ((len = getline (line, MAXLINE)) > 0) if (len > max) { max = len; copy (line, save); } if (max > 0) fprintf (stdout, "%s\n", save); fflush (NULL); } /*******************/ int getline (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') { s[i] = c; ++i; } s[i] = '\0'; return (i); } /*******/ void copy (char s1[], char s2[]) { int i; i = 0; while ((s2[i] = s1[i]) != '\0') ++i; }