// file: my first program // #include #include #include #define MAX_LEN 9999 #define MAX_NLINES 99999 // my main program starts here // int main(int argc, char** argv) { FILE* fp = fopen(argv[1], "r"); char str[MAX_LEN]; char* mstr[MAX_NLINES]; long linenum = 0; while (fgets(str, MAX_LEN - 1, fp) != (char*)NULL) { // allocate space // long len = strlen(str); mstr[linenum] = new char[len + 1]; // copy the data // strcpy(mstr[linenum], str); // increment the line number // linenum++; } // deallocate memory // while (linenum > 0) { delete [] mstr[linenum--]; } fclose(fp); // exit gracefully // return 0; }