#include #include const int LINELEN = 256; const int MAXLINES = 1024; char* lines[ MAXLINES ]; int read_lines(istream& in) { int k, n = 0, m = LINELEN + 2; char *buf, *s; buf = new char[m]; while( in.getline(buf, m, '\n') ) { k = strlen(buf); // line length if ( n >= MAXLINES ) // too many lines return(-1); else if ( k == m-1 ) // line too long return(-n); else if ( (s = new char[k+1]) == NULL ) return(-1); // no free store else { strcpy(s, buf); // copy buffer into s lines[n++] = s; // put s on array lines } } return(n); // total number of lines } int main() { int j = read_lines(cin); for ( int i = 0; i < j; i++) cout << lines[i] << endl; return(0); }