Strings in C
📘 C
👁 27 views
📅 Dec 22, 2025
⏱ Estimated reading time: 1 min
A string in C is a sequence of characters stored in an array of type char and terminated by a null character ('\0').
Declaration of String
Initialization of String
Input and Output of Strings
Using scanf() and printf()
Note: scanf() stops reading at whitespace.
Using gets() and puts()
Note: gets() is unsafe and not recommended.
Using fgets() (Recommended)
String Handling Functions
(Require #include )
| Function | Description |
|---|---|
strlen() | Finds length |
strcpy() | Copies string |
strcat() | Concatenates strings |
strcmp() | Compares strings |
strlwr() | Converts to lowercase |
strupr() | Converts to uppercase |
Example Program
Difference Between Character Array and String
-
Character array may not end with
'\0' -
String must end with
'\0'
Summary
-
Strings are character arrays ending with null character
-
Stored using
chartype -
string.hprovides string functions -
fgets()is safer for input
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials