// file: $(LAB 07)/mread.cc // // this program demonstrates how to read a matrix as a vector // of vectors. each rows of the matrix can have a different size. // // modified: // 20181116 (JP): initial version // // local include files // #include "Matrix.h" // synopsis: // // mread.exe // // : the name of the file to read // // examples: // // mread.exe m1.txt // //============================================================================= // function: main // int main(int argc, char** argv) { // open the input file for reading // FILE* fp = fopen(argv[1], "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "%s: error opening file (%s)\n", argv[0], argv[1]); return(-1); } // load the matrix into our structure // MATRIX mat; if (load(mat, fp) == false) { fprintf(stdout, "%s: error reading matrix (%s)\n", argv[0], argv[1]); return(-1); } // display the matrix // if (display(stdout, mat, (char*)"matrix:") == false) { fprintf(stdout, "%s: error displaying matrix (%s)\n", argv[0], argv[1]); return(-1); } // close the file // fclose(fp); // exit gracefully // return(0); }