Uploaded September 2026 | Updated November 2026, 3 days ago
Learn how to read String Input in C using character arrays and how to display string values using printf().
In this tutorial, we first see how to display an entire C String using printf() with the %s format specifier instead of accessing and printing individual characters using a loop.
Then we learn how to take String Input using scanf() with %s and store the input directly in a Character Array. We also understand why the address-of operator is not used with the array name in this case and how scanf() automatically adds the String Termination Character.
Next, we discuss important problems with scanf() for reading strings. We see how to limit the maximum number of characters that scanf() can read to prevent writing beyond the Character Array. We also see why %s stops reading when it encounters whitespace and how a scanset can be used to read input containing spaces.
After that, we use fgets() as another approach for reading String Input. You will learn how to specify the Character Array, maximum input size, and stdin when using fgets().
We also discuss an important behavior of fgets(): when there is enough space, it can store the newline character entered by the user. We remove this newline manually by finding '\n' and replacing it with the String Termination Character '\0'.
Finally, we briefly see how a function from string.h can be used to locate the newline character and how sizeof can be used with fgets() instead of manually specifying the Character Array size.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial
Learn how to read String Input in C using character arrays and how to display string values using printf().
In this tutorial, we first see how to display an entire C String using printf() with the %s format specifier instead of accessing and printing individual characters using a loop.
Then we learn how to take String Input using scanf() with %s and store the input directly in a Character Array. We also understand why the address-of operator is not used with the array name in this case and how scanf() automatically adds the String Termination Character.
Next, we discuss important problems with scanf() for reading strings. We see how to limit the maximum number of characters that scanf() can read to prevent writing beyond the Character Array. We also see why %s stops reading when it encounters whitespace and how a scanset can be used to read input containing spaces.
After that, we use fgets() as another approach for reading String Input. You will learn how to specify the Character Array, maximum input size, and stdin when using fgets().
We also discuss an important behavior of fgets(): when there is enough space, it can store the newline character entered by the user. We remove this newline manually by finding '\n' and replacing it with the String Termination Character '\0'.
Finally, we briefly see how a function from string.h can be used to locate the newline character and how sizeof can be used with fgets() instead of manually specifying the Character Array size.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial










