Home > Tutorials > C Tutorials > Programming in C: Escape Characters and Tabs

Programming in C: Escape Characters and Tabs

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:

  1. newline character: \n
  2. tab indent: \t
  3. 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:

#include <stdio.h>
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.

#include <stdio.h>
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.

About Michael Boguslavskiy

Michael Boguslavskiy is a full-stack developer & online presence consultant based out of New York City. He's been offering freelance marketing & development services for over a decade. He currently manages Rapid Purple - and online webmaster resources center; and Media Explode - a full service marketing agency.

Check Also

Installing Gnome Software Center on a Chromebook

Linux is pretty much all the rage these days when it comes to Chromebooks – ...

Like every other website, this site uses cookies to analyze our traffic. Cookies may also be utilized by our advertisers and partners. By using this website you agree to the use of said cookies. More Information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings, continuing to navigate past this message, or you click "Accept" below then you are consenting to the use of cookies on the Rapid Purple website.