===== strrchr =====
#include
char *strrchr(const char *str, int c);
===== description of strrchr =====
strrchr () is a string function that finds the last occurrence of a character in a string. As a result, the pointer comes to this character or the null pointer if this character is not found.
In the following example, a string is read by fgets. fgets hangs at the end of a New-line character (\ n). We are looking for a pointer to this character and replace it with a '\ 0' characters.
===== strrchr C Sourcecode Example =====
/*
* strrchr example code
* http://code-reference.com/c/string.h/strrchr
*/
#include
#include
int main( void )
{
char string[]="The answer might 42, if the Earth v 1.0 not exist anymore";
char *ptr;
ptr = strrchr (string, ',');
if (ptr != NULL) {
*ptr = '\0';
}
printf ("%s\n", string);
return 0;
}
==== output of strrchr c example ====
The answer might 42