- Everyone's favorite C language
output function seems to be printf.
In most C courses it's the first function you learn because
it's included in the traditional Hello, World! program.
But the function has far more
power than just spewing out text.
In this movie I introduce you to the printf function.
It's another text output function but
one with far more power than puts.
I'll also show you how to incorporate
escape sequences into strings.
In it's most basic form the printf function sends
a string of characters to standard output.
That means it displays text on the screen.
The printf function is defined in the stdio header file.
The printf function is used twice
in this code in lines five and six.
In this mode printf works a lot like the puts function.
The argument for printf is a single string held
between the functions parentheses.
The string is enclosed in double quotes.
Build and run this code.
The program doesn't air the output is as it should be.
Unlike puts however the printf function doesn't
add a new line character at the end of the string.
Yes, even though two statements are used on two lines
of code the output is one long string.
To add the new line which is like pressing the enter key
at an end of a line you must specify an escape character.
Edit line five to insert a backslash and a little n
before the ending double quote.
In some editors the backslash n appears in
a different color, showing that it's special.
Save the changes.
Build and run.
Now you see two lines output.