CPS 202
Using Visual C++


Creating a new program

  1. Start Microsoft Visual C++
  2. Click on the "new file" button, or click File|New. The empty window that opens up will contain your program code.
  3. Type your code.
  4. Save your code - it is strongly suggested that you save your work to the hard drive (use the P: drive for best results). Save it with this format: name.c
    The should must be eight characters or fewer - be sure that if you write code at home that you use eight characters or less if you will be using the code on the CCV computers. If you wish to use long filenames, it is best to place your file in a ZIP file and then save the ZIP file to your diskette.
    For best results, save the .c file into a new, separate folder.
  5. Once the file is saved, the source code must be compiled. Click Build|Compile
  6. Visual C++ will ask if you would like to create a default project workspace. Click Yes.
  7. If there are errors, they will display in the box on the bottom of the screen.
  8. Correct any errors and click Build|Compile until the source code is error free.
  9. The compiled code must be built into an executable. To do this, click Build|Build (or hit F7).
    At this stage, you may get some errors. The error "LINK : LNK4073: cannot create map for .ILK file; linking nonincrementally" is not severe. If you get it, just proceed.
  10. Finally, run your program: Click Build|Execute, or click the Red Exclamation Point button.

When you are done with your program, save it to diskette (or save it in some other way, such as to a ZIP file then to diskette,m emailing it to yourself, or ftp to your server). Close the source code window and close the workspace. Click on the "New window" button again, or click File|New.

If you do not close the workspace, Visual C++ will probably try to compile your two .c files together, which is a Bad Thing.


Compiling on Diskette

Compiling on diskette is not recommended. First, diskette access times are extremely slow. Second, because names on a diskette must be of the DOS 8.3 format, Visual C++ will only allow you to compile your file once and will then refuse to compile again. Lastly, because Visual C++ creates several auxilliary files, your diskette can quickly fill up.


Compiling using other compilers

You can download Turbo C++ from the Borland website. This is a DOS compiler which should run just fine in any version of Windows (though I've heard that Windows ME users have trouble with it). It is small, fast, and robust, but lacks any features of Windows. Turbo C++ wil compile C or C++ files.

Several "Learn C" books include a copy of Microsoft's QuickC program. Some versions of QuickC will not create stand-alone EXE files (you will only be able to execute the program from within QuickC). QuickC is, like Turbo C++, small and fast. It will compile only C files.

Visual C++, Turbo C++, and QuickC all use an "IDE," an Integrated Development Environment. This allows you to write, compile, build, and run programs all within one program or window.

If you have access to a Unix/AIX/FreeBSD/Linux machine, these almost always have a compiler installed. To see if you do, open a command line window and at your user prompt, type "cc" and press enter. If cc is not available, try "gcc". To compile a file, the command would be:

cc name.c -o name

where "name.c" is your source file and "name" is the executable to create. To write the source file, you would need to use a text editor such as vi, joe, or emacs.