There is a set of special characters, called escape characters, which add special things to your printf statements. Escape characters begin with a backslash: \ and are followed by a letter or symbol, such as:
- newline character: \n
- tab indent: \t
- beep sound: \a
The most important escape character is the newline character, which inserts a blank line in your text. The newline character is written: \n. Let’s edit our first.c program to add some newline characters:
void main( )
printf(“\nWe are learning C today.\n“);
printf(“\nNewline characters add blank lines.\n“);
Save your first.c source code. Compile it. Link it. Run it. With the newline characters, your text will appear like this:
|We are learning C today. Newline characters add blank lines.
Did it work? If you got error messages during the compilation, go back into your editor and fix your mistakes.
Let’s try another escape character: \t, which inserts a tab (automatic spacing) in your text.
void main( )
printf(“\nThere is a tab here: \t Can you see the spacing?”);
printf(“\nHere it is again: \t Can you see it?”);
Save your source code as tab.c. Compile it. Link it. Run it. With the tabs, your text will appear like this:
|There is a tab here:
Here it is again:
|Can you see the spacing?
Can you see it?
Continue on to Variables.