PF LEC7
PF LEC7
FUNDAMENTALS
STRINGS
Strings are used for storing text/characters.
For example, "Hello World" is a string of characters.
To output the string, you can use the printf() function together with
the format specifier %s to tell C that we are now working with
strings:
ACCESS STRINGS
You can also loop through the characters of a string, using a for
loop:
ANOTHER WAY OF CREATING STRINGS
String Length
For example, to get the length of a string, you can use the
strlen() function:
EXAMPLE OF STRLEN
It is also important that you know that sizeof will always return the memory size (in bytes), and not the actual string length:
CONCATENATE STRINGS
To copy the value of one string to another, you can use the strcpy()
function:
COMPARE STRINGS