Built-in C Strings Function
Learn how built-in string functions work.
We'll cover the following...
Built-in string functions in C++
We have discussed string functions in detail so far. Now we’ll discuss the built-in functions of the string libraries. Previously, we had to write detailed code for each function. Did you know instead of reinventing the wheel, we can simply achieve all that functionality by calling existing library functions?
For example, we need to call the functions to copy or reverse the string. We don’t need to write complete code. This will make the program simple. To use the string functions, we’ll include standard libraries:
cstring: For thestrcpyandstrcatfunctionscctype: For thetolowerandtoupperfunctions
We have a complete chart of string functions below:
String Functions
Function | Description |
| To check the string length |
| To copy the content of the string |
| To concatenate two strings |
| To compare two strings |
| To convert the string into lowercase |
| To convert the string into uppercase |
Here’s the example program which uses all these helper functions, which are available in different libraries. There are several other functions in the library that we may explore online.
In line 40, strcmp compares character by character. If the characters from the 0th index are equal, it moves forward. Otherwise, it returns the difference in ASCII between the two characters.
Therefore, a positive returned value means the first string is lexicographically greater than the second. A negative returned value means the second is greater, but when 0 is returned, it means both strings are equal.
Find the mistake
Look at the code below and see if you can find out why strcat() gives the unexpected output: