Program #1: Questions and Answers

These are the questions I have received thus far on Program #1, and my answers.
Borland C++ does not terminate the program when I type Ctrl-d, what do I do?
Ctrl-d for ending input is a Unix-ism that isn't universally adopted on Windows or Mac. Ctrl-z might work. Or, you can define a special character to terminate the input, AS LONG AS YOU DOCUMENT WHAT IT IS. For example, it is common to end input with the '.' character, which can be checked for at the beginning of a read loop:
while (cin >> buffer) {
	if (buffer[0] == '.')
		break;  // exit loop
	...
}
I don't understand how I am supposed to turn in my program?

If you are on a Mac or PC, then you should put all your source files (.txt, .h, .C) on a diskette and turn it in. If you created a "project" using Borland C++, MS Visual C++, Metrowerks C++, then you should save the entire project to the diskette so that it can be built and tested easily.

You can also email the files, but will first need to use a utility like WinZip to build a compressed archive of the files. To email a binary compress ZIP archive, you need to either send it as an attachment using a MIME capable mail programs (like Eudora, Netscape Mail, Microsoft Exchange, Z-Mail, etc.) which will automatically do a "base64" character encoding of a binary file, or you can "uuencode" the file into ASCII.(You have to do this encoding because many Internet mail systems can only handle 7-bit characters, and binary files use all 8-bits in a byte).

If you are developing on Unix, you should use tar and compress (or GNU gzip) to create a compressed tar archive of your program directory, and then use a MIME capable mail program to send it as an attachment. If you don't have a MIME capable mail program (e.g., pine, mh, exmh, etc.), or you can just 'uuencode' (see man uuencode) the prog.tar.Z file and send the ASCII encoding generated by uuencode.

Why am I getting "Linker errors" trying to build the executable for my program?

When you #include files, such as iostream.h, it defines objects and functions that are external to your program, and are in a library. Usually, the compiler knows where to find the standard C++ libraries to link with your object file files (.o or .obj) to create a runnable program. You may have to specify options to the compiler to tell it where to look if the libraries are not in a "standard" place. On an integrated C++ environment on the PC, this is usually done for you. On Unix, particularly with g++, you may have to tell it where to look if things are not installed in the usual way.

The options to Unix linkers are all the same. You may need the -Lpath/ to specify the path to the library, and -lname to specify the library. If you use gcc instead of g++ as the compiler command, then gcc needs a -l flag to link libg++.a which is where the iostream things (like cout) are found:

% gcc -g myprog.C -lg++
If you use g++ as the driver, then it implicitly includes the -lg++ flag. The -v (verbose) option to gcc and g++ is helpful as it shows you the execution of the preprocessor (cpp), the compiler (cc1plus), the assembler (as) and the linker (ld).

If you are using Borland C++, you set the libary path by going to the Options->Project menu item and click on Directories, and set the path to the .lib files that are needed to link your program. The path is usually set to a default, which should be OK unless you moved something. If you used the TargetExpert to create a Borland IDE project, it will put some .obj and .lib files into your project by default, which are usually needed to link an executable.