C Programming
Use a text editor (I prefer PFE) to create a new file and type the following
lines:
and save it as a file named helloworld.c. We will now need to compile this
program using gcc, which is technically done in a DOS window. Fortunately,
graphically oriented text editors, including PFE and Synedit) have facilities
for compiling directly within the editor environment. I will describe the
procedure using PFE, but it is easily generalizable to the other editors. See
their respective documentation on this web site for more information and links.
First we are assuming that the directory in which the editor is working has
already been designated. (In PFE, this is done by selecting the Change
Directory... option in the File menu.) Next we click on the
Execute menu and
select the DOS Command to Window... option. Note also that the keystroke
shortcut for invoking this window is to simply press the F11 key, which is what
we'll do for the remainder of this explanation. Using either method, a dialog
box appears, looking like this:
Note that we have typed the compiler invocation in the Command: window
already. This is a basic invocation of the compiler and, as you become more
proficient in using gcc, you'll probably use others. This is enough to get your
started, though and what it means is this: Compile the C language input file
called helloworld.c and produce, as output, an executable file (for your Windows
box, in this case) called helloworld.exe. Note also that we have used the DOS
symbol "." to denote the present directory as the one in which the (i)
the input file is to be found, and (ii) the output executable file to be placed.
The "present" directory was defined using the Change Directory command
above.
Note: Invoking the Execute DOS
Command and Capture Output dialog box using the F11 key allows the capture of
the text printed in the DOS execution window which briefly appears. The
resulting captured text, appearing in the CommandOutput1 window in the PFE
workspace is not a DOS window. What looks like DOS command lines are not,
unfortunately. You cannot type in additional DOS commands at what looks like
the new DOS prompt. You'll still have to invoke the DOS command using the F11
key again.
To produce this executable now, press the OK button. You'll see a DOS window
open briefly, showing the progress of the compilation process. When gcc has
finished, the temporary DOS window will close and PFE will open a second window
in the PFE workspace showing what happened (i.e., it has "captured the
output").
No error messages were produced, in this the best of all possible worlds
(apologies to Voltaire), and we can see that an executable file was created by
producing a listing of the files currently in the directory using the F11 key:
or using Windows
Explorer to see:
We can now run the executable helloworld.exe by either double-clicking it in
the Windows Explorer or by executing a DOS command from within PFE using the
F11
key:
Press the OK button to see the result:
Congratulations! You have a working C/C++ compiler running on your laptop PC!