Nearby lessons

44 of 72

C - String Output

Learn how to display strings in C using printf(), puts(), and fputs(). Understand their basic differences through simple examples.

Displaying a String Using printf()

We can use printf() to display a string on the screen.

The %s format specifier is used to display a string.

Example01
Loading editor…

Displaying Multiple Strings Using printf()

We can display multiple strings and messages using printf().

Use \n when you want to move the output to the next line.

Example02
Loading editor…

Displaying a String Using puts()

The puts() function displays a string and automatically moves the cursor to the next line.

It is useful when we want to display a simple message.

Example03
Loading editor…

Displaying a String Using fputs()

The fputs() function displays a string on the specified output stream.

For screen output, we can use stdout. Unlike puts(), fputs() does not automatically add a newline.

Example04
Loading editor…

Difference Between printf(), puts(), and fputs()

These functions can display strings, but they have some differences.

  • printf() supports format specifiers such as %s and %d.
  • puts() displays a string and automatically adds a newline.
  • fputs() displays a string without automatically adding a newline.

For beginners, use printf() when you need to display variables with labels, and use puts() for simple messages.

Example05
Loading editor…

Common Mistakes

  • Using %d instead of %s to display a string.
  • Expecting printf() to move to the next line without using \n.
  • Forgetting that puts() adds a newline automatically.
  • Expecting fputs() to add a newline automatically.
📝 Key Takeaways
  • printf("%s", name) displays a string.
  • The %s format specifier is used to display a string.
  • puts() automatically adds a newline after the string.
  • fputs() does not automatically add a newline.
  • Choose the output function according to your requirement.

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.