int main() { char s[1000]; m_getline(s, 10); printf("%s\n", s); return 0; }
/* print longest input line */ main() { int len; /* length of current line length */ int max; /* length of longest line so far */ char line[MAXLINE]; /* current input line */ char longest[MAXLINE]; /* longest line so far */ max = 0; while ((len = m_getline(line, MAXLINE)) > 0) if (len > max) { max = len; copy(longest, line); } if ( max > 0) /* there was a line */ printf("%s", longest); return 0; }
int readlines(char **lineptr, int maxlines) { int len, nlines; char *p, line[MAXLENGTH]; nlines = 0; while ((len = m_getline(line, sizeof line)) > 0) { if (nlines >= maxlines) { return -1; } else { if (line[len - 1] == '\n') line[--len] = '\0'; p = m_alloc(len + 1); strcpy(p, line); *(lineptr + nlines++) = p; } } return nlines; }