![]() |
VOOZH | about |
string.h is a standard header file in the C language that contains functions for manipulating strings (arrays of characters). <string.h> header file contains some useful string functions that can be directly used in a program by invoking the #include preprocessor directive.
Syntax:
#include <string.h>
Example:
Str1: Geeksfor Length of Str1 before concatenation: 8 Str1: GeeksforGeeks
<string.h> header file contains the following functions:
Function Name | Function Description |
|---|---|
| Returns the length of the string. | |
| Copy one string to another. | |
strncpy() | Copy first n characters of one string to another. |
| Concatenates two strings. | |
| Concatenates first n characters of one string to another. | |
| Compares two strings. | |
strncmp() | Compares first n characters of two strings. |
strchr() | Find the first occurrence of the given character in the string. |
strrchr() | Finds the last occurrence of the given characters in the string. |
| Find the given substring in the string. | |
| Returns the span of the source string not containing any character of the given string. | |
| Returns the span of the source string containing only the characters of the given string. | |
| Finds the first occurrence of any of the characters of the given string in the source string. | |
strtok() | Split the given string into tokens based on some character as a delimiter. |
strcoll() | Compares two strings that are passed. |
| Initialize a block of memory with the given character. | |
memcmp() | Compares two blocks of memory. |
| Copy two blocks of memory. | |
| Moves two blocks of memory. | |
memchr() | Finds the given character in the block of memory. |
Example:
Length of Destination String: 8 tempDestString after strcpy(): Geeks destString after Concatenation: GeeksforGeeks Comparing destString with sourceString: 102 Comparing first 5 characters: 0 Searching sourceString in destString: GeeksforGeeks