Monday 02/13/2006, CISC181, the day after the big snow If we compile readNums.cc with CC readNums.cc we get a file called: a.out we can do the same thing with g++ readNums.cc However, a better way to compile is: make readNums When we return a value through return 0; // in the main return 1; // in the main exit (13); // anywhere the values we can return are 0 through 255. (If we return a larger value, the upper bits get through away... only 8 bits of unsigned integer are retained. So, for example, 500 gets returned as 244, because 500 = 256 + 244. 1029 gets returned as 5, because 1029 = 1024 + 5. You can see what gets return by doing echo $? Running the program with a nums.dat file 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.