Strrchr() function in C
The strrchr() method in the C standard library looks for the final instance of a given character within a string. The function returns a pointer to the final instance of the character in the string. The function returns a null pointer if the character cannot be located. The string.h header file contains a declaration for the strrchr() function.
The strrchr() function has the following syntax:
Two arguments are required by the strrchr() method.
It is a reference to the search string.
It is used to look for in the character.
A pointer to the last instance of the character c in the string str is returned by the strrchr() function. The function returns a null pointer if the character cannot be located.
An example of how to use the strrchr() function is as follows:
The following is the program's output: The last occurrence of the character 's' in the string is at position 10
The strrchr() function can be utilized to locate a character's final occurrence inside a string. It can be helpful for a number of purposes, like locating the final occurrence of a delimiter in a string or the final occurrence of a certain term.
Example: 2 when the string contains no instances of the character:
If the character being searched for cannot be found in the input string, the strrchr() function returns a NULL pointer.
y is not present in JavaTpoint
There are several more standard library functions that can be used to search for characters in strings in addition to the strrchr() method. These activities include are:
This function looks for a particular character in a string only once.
This function looks for a given substring's first occurrence within a string.
This function looks for a string's first instance of a provided collection of characters.
This function calculates the length of the longest prefix in a string that doesn't include any of the characters you specify.
The longest prefix of a string that solely comprises characters from a set of specified characters is returned by this method. Several third-party libraries offer more string-searching functionality in addition to the standard library functions. These libraries can be employed to carry out more difficult string-searching tasks, like regular expression matching.
The strrchr() function can be used to locate a character's final appearance in a string quickly and easily. Since the function is a part of the standard library, every C implementation has access to it. Any C programmer can benefit from the strrchr() function, which can be used to carry out a variety of string-searching tasks.