C programming strrchr string.h

In C programming the <string.h> strrchr function locate the last occurrence of a character in a string.The declaration of the string is given below.

char *strrchr(const char *s, int c);

s -The string from which the character is to be located.

c -An ‘int’ value converted to ‘char’,whose last occurrence is to be located in ‘s’.

Return type
char* -Returns a pointer to the character,or a null pointer if ‘c’ does not occur in the string.

Note the null-terminating character is part of the string,in other words if the character passed is a null,the character to be searched for in the ‘s’ string is a NULL.

Code example

char s1[]=”Elephant” , *ret ;

int c=’E’ , null=’\0′ ;

ret=strrchr(s1, c);

printf(“ret=%c”, *ret);

ret=strpbrk(s1 , null);

printf(“\nret=%c”, *ret);



The second returned value is NULL.

Related links

->C strcspn string.h

->C strpbrk string.h

->C strchr string.h

->C strspn string.h

->C strstr string.h