// file: lecture_08example.cc // // local include files // #include "example.h" // method: main // // main program starts here // int main(int argc, char** argv) { // grab a value from the command line // long N = atoi(argv[1]); /* // loop N times // for (long i = 0; i < N; i++) { // check the value of i // if (i < 2) { fprintf(stdout, "i [%d] is less than 2 (%d)\n", i, N); } else if (i < 4) { fprintf(stdout, "it is a great day for a quiz\n"); } else if (i == 5) { fprintf(stdout, "i is equal to 5\n"); } else if (i != 6) { fprintf(stdout, "i is not 6\n"); } else { fprintf(stdout, "*** warning *** (%d)\n", i); } } */ // demonstrate logical operators // long M = atoi(argv[2]); /* if (N == M) { fprintf(stdout, "N == M\n"); } // else if ((N % 2) && (M % 2)) { // fprintf(stdout, "both N and M are not a multiple of 2\n"); // } else if ((N % 2) || (M % 2)) { fprintf(stdout, "N or M is not a multiple of 2\n"); } else if (((N != M) || (N % 2)) && (M % 2) && (N > M)) { fprintf(stdout, "N and M are not equal\n"); } */ // open a file // bool status = false; FILE* fp = fopen(argv[1], "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "hello world\n"); exit(0); } long i = 0; char buf[999]; while (fgets(buf, 999, fp)) { fprintf(stdout, "%d: %s", i++, buf); } // close the file // fclose(fp); // exit gracefully // return(0); }