Let's begin creating our Hello, world! program.
Before we begin creating files, create a directory on your computer where you will save all of the work for this book. Perhaps you will create it in your $HOME directory, or in your Documents folder. My advice is to put it somewhere in a user directory of your choice. Let's go ahead with our program:
- Open a Command Prompt, Terminal window, or console (depending on your OS).
- Navigate to $HOME or ./Documents, or wherever you chose to work from, and create a directory for the programs you'll write in this book. Do this with the following command:
$ mkdir PacktLearnC - Make that directory your current working directory with the following command:
$ cd PacktLearnC - Make a new directory for this chapter with the following command:
$ mkdir Chapter1_HelloWorld
- Make that directory your current working directory with the following command:
$ cd Chapter1_HelloWorld - Picking the text editor of your choice – any will do – open the text editor either from the command line or from the GUI (depending on both your OS and your preference of which one you wish to use):
- From the command line, you might enter $ myEditor hello1.c, or just $ myEditor, and later, you will have to save the file as hello1.c in the current working directory.
- Enter the following program text exactly, all while paying attention to spacing, {} versus () versus "" (these double-quotation marks are the key next to the ; and : keys) versus <>, with particular attention being paid to #, \, ., and ;:
#include <stdio.h>
int main()
{
printf( "Hello, world!\n" );
return 0;
}
- Save your work and exit the editor.
- Verify that hello1.c exists by listing the directory and verifying that its file size is not zero.
Congratulations! You have completed your first editing phase of the program development cycle.