Monday 02/13/2006, CISC181, the day after the big snow We started with three versions of the readNums.cc program written by students: (1) a variation by bwadswor (Burke) to compute the average (2) a variation by Nevin (nev) to compute min (3) a variation by Brian (bflad) to compute max In each case we saw the importance of doing: read while (not end of file) { process read } e.g. infile >> x; while (!infile.eof()) { // do something with x sum += x; infile >> x; } We'll show what happens if you DON'T do that today or Wednesday. Next, we'll show a different way to compile: instead of CC readNums.cc which gives us an a.out file or g++ readNums.cc which also gives us an a.out file We can just type: make readNums Note: we leave off the .cc That echos a longer version of the compiler command, like so: > make readNums CC -o readNums readNums.cc > IF the readNums.cc file is "newer" than the most recent version of readNums, OR if readNums (the executable) does not exist, it will compile the program. If I've already compiled readNums.cc into readNums, and if I have NOT made any changes, I just get something like this: > make readNums `readNums' is up to date. > Now, to run the program, instead of ./a.out I do ./readNums > ./readNums Could not open nums.dat, sorry! > Here, we get the error message because we don't have a nums.dat file: > ls 02.13.1.25pm.txt 02.13.1.25pm.txt~ readNums readNums.cc readNums.cc~ > Now, one more thing.. remember I told you that exit(1) vs. return 0 is something we could see at the command line. Here's how: echo $? Next time: Show what happens with an empty file Look at the code where infile >> x is not at the top and bottom Look at how to write the code so that if there are characters in the file it still works.