Syntax of strchr() in C

char *strchr(const char *str, int ch);

strchr in C

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 or not, if the character is found it returns the pointer to it otherwise it returns a null pointer indicating the character is not found in the string.

Similar Reads

Syntax of strchr() in C

char *strchr(const char *str, int ch);...

Parameters of strchr() in C

str: It is the string in which we have to search the character. This string is a constant character pointer, meaning that the function will not modify the string.ch: It is a character to be searched in the string. Though passed as an int, it represents a character and is cast internally. This allows strchr() to be used with character values, including special characters and ASCII values....

Return Value of strchr()

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....

Examples of strchr() in C

Input: str1 = "GeeksforGeeks"ch = sOutput: Character 's' is found at position: 4...

Conclusion

The strchr() function is an important tool for handling and manipulating strings. It allows for efficient searching of characters within strings and can be utilized in various scenarios, such as parsing input, processing text, and more. We can perform complex string operations with ease, making our code more efficient and effective in handling textual data....