Strings
C Strings
C has very minimal support for character string. In C a string is just an array of characters.
A C string is just an array of char
with a '\0'
null termination character signalling the end of the string.
The compiler represents string literals as arrays.
There are several library functions that are usefull when working with strings on C.
strcpy
{
char localString[10];
strcpy(localString, "test");
}
The owner is responsible for allocating array space that is large enough to store whatever the string will need to store. Many times programmers will leave the array size bigger than what is needed. For example localString[1000]
. A better solution to this is to allocate the string dynamically in the heap so it has just the right size.
char* is often used to represent strings – A pointer to an array of characters.