// file: lecture_10/example.cc // // local include files // #include "example.h" // method: main // // main program starts here // int main(int argc, char** argv) { // declare an array // char buf[999]; // opens a file // FILE* fp = fopen(argv[1], "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "*> an error has occurred (%s)\n", argv[1]); } // loop over the file and read every line until we hit an EOF // char* ptr = fgets(buf, 999, fp); while (ptr != (char*)NULL) { fprintf(stdout, "1: buf = %s", buf); ptr = fgets(buf, 999, fp); } // rewind the file // rewind(fp); // loop over the file and read every line until we hit an EOF // while (fgets(buf, 999, fp)) { fprintf(stdout, "2: buf = %s", buf); } // close the file // fclose(fp); // call a function // if (my_function((long)1, (long)2)) { fprintf(stdout, "my_function worked!!!!\n"); } else { fprintf(stdout, "my_function did not work :(\n"); } // exit gracefully // exit(0); }