Appendix A
Commonly Used String Manipulation Functions
Header Required: string.h
- strcpy (char dest[], const char source[]);
- This function copies the string source into the string dest, including the
end of string terminator '\0'. The dest array must be large enough to hold
all of the characters in source array.
Click here for an example
- strncpy (char dest[], const char source[], int n);
- This function copies n characters from the string source into the string dest, including the
end of string terminator '\0'. The dest array must be large enough to hold
all of the characters copied from the source array.
Click here for an example
- strcat (char s1[], const char s2[]);
- This function appends the string s2 onto the end of string s1, including the
end of string terminator '\0'. The array s1 must be large enough to hold the
extra characters being appended from the s2 array.
Click here for an example
- strncat (char s1[], const char s2[], int n);
- This function appends n characters from the string s2 onto the end of string s1, including the
end of string terminator '\0'. The array s1 must be large enough to hold the
extra characters being appended from the s2 array.
Click here for an example
- int strcmp (const char s1[], const char s2[]);
- This function compares the strings s1 and s2. If s1 and s2 are identical then the
function will return 0. If s1 is alphabetically lower than s2 then a negative
value is returned. If s1 is alphabetically higher than s2 then a positive value is
returned.
Click here for an example
- int strncmp (const char s1[], const char s2[], int n);
- This function compares the first n characters of the strings s1 and s2.
If the first n characters of s1 and s2 are identical then the
function will return 0. If the first n characters of s1 are alphabetically lower
than s2 then a negative value is returned. If the first n characters of s1 are
alphabetically higher than s2 then a positive value is returned.
Click here for an example
- int strlen (const char source[]);
- This function returns the number of characters in the source array, not including the
end of string terminator '\0'.
Click here for an example