Example Programs

Hey, you have to start somewhere, and it is a time honoured tradition to make your first C program a "Hello world!" program. Everyone who has ever learned C wrote one of these. It is just a very simple program to display "Hello world!" on the screen.

Of course it is also a time honoured tradition to not actually write your own "Hello world!" program, but to "borrow" someone else's and learn how that works. For this purpose, we'll use the one which comes supplied with Pelles C.

Simply open up the Pelles C program and go to "File->Open" on the menu. Find the "Pelles C" directory (probably in "Program Files") and then navigate down the directory tree to "..\PellesC\Projects\Samples\Standard C\hello\". Double click on the little round ball which says "hello" next to it. This is the project file which goes with this program. The other file called "hello" is the actual C program itself, which you'll see in a moment.

Now on the right hand side of the screen, you'll see all the files associated with this project. Double click on the one which says "hello.c".

It is a standard convention that all C programs be given the extension ".c" to identify them. Such a file is known as a source file. It contains your source code.

In the editor, this "Hello world!" program will now be visible. This is a complete C program.

top

Running the Programs

OK, let's run the program and see what it does. On the menu at the top, simply click "Project->Execute hello.exe".

The first thing which happens is the compiler is run and builds the file "hello.obj". (You'll see a list of things that have happened on the left hand side of the screen at about the middle.) Next the linker turns the single .obj file into an executable file "hello.exe". (The file "projdefs.tag" is irrelevant and you can ignore it. This file is peculiar to Pelles C.)

After a second or so, the program "hello.exe", which now exists as an actual file on your hard drive, is executed. A DOS box pops up and you'll see your program running. It does exactly as stated, and displays "Hello world!" on the screen and then exits. (Note that the DOS box then prompts you to press a key when you are finished, to close it. This is not actually part of the program itself.) Once you press a key, you are returned to the Pelles C editor.