![]() |
VOOZH | about |
The strchr() function in C is a predefined function in the <string.h> library. It is used to find the first occurrence of a character in a string. It checks whether the given character is present in the given string. If the character is found, it returns the pointer to its first occurrence otherwise, it returns a null pointer, indicating the character is not found in the string.
The strchr() function returns a pointer to the first occurrence of the character in the string. If the character is not found, the function returns NULL. Here, the return type is char *, which allows direct access to the character and subsequent characters in the string from the found position.
The following examples illustrates how we can use strchr() in various scenarios.
Using strchr() to check the existence of character in a string and print its first occurrence.
Character 's' found at position: 4
Using strchr() function to parse the string until a given delimiter is found.
Username: GeeksforGeeks Password: abc@123