// file: lecture_08/example.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]); /* for (long i = 0; i < N; i++) { // check the value of i // if (i < (long)2) { fprintf(stdout, "i [%d] is less than 2 (%d)\n", i, N); } else if (i < (long)4) { fprintf(stdout, "it is a great day for a quiz\n"); } else if (i == (long)5) { fprintf(stdout, "i is equal to 5\n"); } else if (i != (long)6) { fprintf(stdout, "i (%d) is not 6\n", i); } else { fprintf(stdout, "*** warning *** (%d)\n", i); } fprintf(stdout, "done with if/else\n"); } */ // 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 fail the modulo operator\n"); } else if ((N % 2) || (M % 2)) { fprintf(stdout, "either N or M failed the modulo operator\n"); } else if ((N != M) || (N % 2) && (M % 2) && (N > M)) { fprintf(stdout, "N and M are not equal\n"); } /* some useful code // open a file // bool status = false; FILE* fp = fopen(argv[1], "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "%s: my program failed to open file (%s)\n", argv[0], argv[1]); exit(0); } // let's read the file line by line // 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); }