(Last Mod: 27 November 2010 21:38:40 )
Start with the C Source Code Template for this course. With most browsers you can retrieve this file by right-clicking on the link and selecting "Save Target As" from the drop down menu. Save this file to a convenient place on your computer. If you are using a network computer at the university do NOT save it to any of the computer's hard drives; instead, save it to your network drive or an external medium such as a USB drive. Do not use a floppy disk as this will result in very slow compile times and possibly even compile failures due to disk size limitations.
On most computers where the Borland TurboC Integrated Development Environment (IDE) is installed you can launch it by selecting the "Start" taskbar button, then selecting "Programs", then "Turbo C++ 4.5", then finally "Turbo C++".
From Menu Bar: File - Open (Leftmost button on the standard Toolbar)
On the Dialog Box that is brought up, use the Drives list (lower-right region) to first select the drive that the file is located on and then use the Directories list (upper-right region) to navigate to the correct directory. The template.c should now be in the File list (upper-left region). Open the file by double-clicking the name or single-clicking it and selection the Open button.
Note: You can also create a new file instead of opening an existing one. If you do, be sure to use the correct extension when you save the file as the default will likely be *.cpp and you need *.c.
From Menu Bar: File - Save As
Save this file with an appropriate name and in an appropriate place. If you do not yet have an assigned student identifier, use the first three digits of your last name followed by the first digit of your first name. In most cases, this will be your student identifier. However, be sure not to submit any code for grading unless you know and use your assigned identifier.
Do not work off of a floppy when at all avoidable. Turbo C creates some rather large files and you may run out of disk space. At the very least, your compile and link times will be much longer than necessary.
If saving a new file, be sure to use a ".c" extension and not the ".cpp" extension that will likely be offered as the default. A *.cpp extension will invoke the C++ compiler which imposes some slightly different rules for C++ code than for C code.
If saving a new file, do NOT blindly save the file in the directory that Borland offers as the default. This is very possibly a directory within the Borland file structure and user files do not belong there.
From the Menu Bar: Options-Project-Compiler-Source
Select "Borland extensions".
This will allow you to use end-of-line comments as well as functions from the "conio.h" library.
You may have to perform this step every time you open this file. The reason is that this is a "project" level setting and you have not created a project - so the compiler has no place to store this setting in such a way that it is associated with this particular file. Projects are not required for single-file programs though you may define one.
Assuming you are working with a copy of the C Source Code Template, perform any modifications necessary. Guidance is provided in the Style Standards.
At this point you would write your program. Since the C Source Code Template is a complete and functional program, we will proceed with the steps necessary to Compile, Link, and Run the program.
From the Menu Bar: Project-Compile
This will compile the code. Errors and warnings will be reported in a separate window.
Remember that compiling is not enough to get your executable file. You must still Link the code.
From the Menu Bar: Project-Make All
This will Link the code. Again, errors and warnings will be reported in a separate window. If you receive a warning about there not being a module definition file specified, ignore it. The defaults are what you want.
If your source code has changed, this selecting this option will recompile it before linking it.
You can force the compiler to compile and link your program from scratch by selecting the Rebuild All option instead of Make All.
From the Menu Bar: Debug-Run
This will launch a window and run your program in it. After it finishes the window will go inactive and you will probably have to close it manually by clicking the 'x' icon in the upper right corner.
If the present window is one not your source code window - for instance, it will probably be the Message window after compiling and/or linking the program - then you will get a "Could not create process." error. This is because you are trying to execute the contents of a window that doesn't contain a program. Select the source code window and try again.
It is a very good idea to save your program before running it. If your program crashes the IDE, then any unsaved data is likely to be lost. The editor files are NOT saved automatically by default.
Normally, when you run your program, it is expected that it will finish execution and then return you to the IDE. If it doesn't, you have a few options to terminate your program depending on why you need to do so.
From the Menu Bar: Debug - Terminate Program
If your program running normally but is waiting for input you can terminate it by selecting this option or by clicking the "x" icon in the upper right corner of the execution window.
If your program is not currently waiting for input or gets into an infinite loop, you won't be able to select the Terminate Program option from the Menu.
Clicking the 'x' icon in the upper right corner of the execution window might work as might right-clicking on the execution window's Task Bar icon and selecting "Close". These may or may not be able to stop it. Give it a few seconds to respond, probably with an "Application Not Responding" dialog box from the Task Manager. Select "End Now".
Take note of the section on Unusual Termination below.
Most of these commands also Hot Key and/or one-click Toolbar shortcuts - to find out what a particular Toolbar button does, position the mouse over a button and read the description in the message line at the bottom of the editor environment window. Learning how to use these shortcuts can be a great time saver.
Once you have compiled your code, you can use the integrated debugging capabilities to track down and correct errors. The debugger has many capabilities - only the most basic will be discussed here.
From the Menu Bar: Debug - Step Over
Executes one statement - if any functions are called, it execute that function at full speed.
From the Menu Bar: Debug - Trace Into
Executes one statement - if a function is called, it will push into that function. It will not push into standard library functions.
From the Toolbar: Click on the button to the right of the lightening bolt.
Place the cursor on a line of executable code in the source code file and click on this button. This can also be invoked by pressing F4. There is no menu item available for this action. If you get a message saying that no address is available for the present line, it probably means that the compiler optimized out that line of code. This may or may not provide a clue as to what is going wrong with your program.
From the Menu Bar: Debug - Terminate Program
If you are debugging your program and want to stop your program, either because you found an error or just because you want to start over, you use this option to terminate the program.
If your program running normally but is waiting for input you can also terminate it this way or by clicking the "x" icon in the upper right corner of the execution window.
Because the IDE and your program's execution window share the same memory space, your program is capable of corrupting the IDE. Anytime your program throws an error or you have to kill it, be prepared to have to close the IDE and reopen it. You may or may not have to do this - if everything looks like it is working okay, it probably is. If in doubt, exit and restart. It is also possible to corrupt the temporary files that the IDE maintains on your drive to the point that you can't re-launch the IDE. If this is the case, log off the computer and log back on. It should not be necessary to reboot the machine.