String 1
String 1
Exploring Strings
Strings
• A string is defined as null terminated character array.
• A string must be terminated by a null – means that we need one
byte extra for holding null character.
• A string constant is null-terminated by the compiler automatically.
• Each character takes one byte in string.
Read Strings from Keyboard
• There are several ways-
• Using scanf() function-
• for string C use “%s” format specifier
• String - input form KB - scanf – 1
• string - input from KB - scanf – 2
Example
Initialize String
Example
STRING.H
• The four most string related library functions are
1. strcpy() – for copy
Example 2
strlen()
strlen (str);
• Example