The strrchr () function in C

Char * strrchr (const char * str, int c) looks for the last occurrence of the character c (an unsigned char) in the string pointed to by parameter str.

Declaring strrchr () function in C

Here is the declaration for strrchr () in C:

 char * strrchr ( const char * str , int c ) 

Parameters

str - A string.

c - This is the character to be located. It is transmitted in int form, but internally it is converted back to char.

Returns the value

This function returns a pointer to the last occurrence of the character in str. If the value is not found, the function returns a null pointer.

For example

The following C program illustrates the usage of strrchr () in C:

 #include #include int main () { int len ; const char str [] = "https://QTM.com/lap-trinh-c/index.jsp" ; const char ch = '.' ; char * ret ; ret = strrchr ( str , ch ); printf ( "Chuoi xuat hien sau dau |%c| cuoi cung la: n|%s|n" , ch , ret ); return ( 0 ); } 

Compiling and running the above C program will result:

The strrchr () function in C Picture 1

According to Tutorialspoint

Previous article: Function strpbrk () in C

Next lesson: strspn () function in C

5 ★ | 1 Vote

May be interested

  • The strspn () function in CPhoto of The strspn () function in C
    function size_t strspn (const char * str1, const char * str2) calculates the length of the first character segment of the str1 string containing the characters in str2
  • The strtok () function in CPhoto of The strtok () function in C
    char * strtok function (char * str, const char * delim) divides the string str into a sequence of tokens separately separated by delim separators (eg comma, ...).
  • Function strxfrm () in CPhoto of Function strxfrm () in C
    the function size_t strxfrm (char * dest, const char * src, size_t n) transforms the first n characters of the src string into the current locale and places them in dest string.
  • The function printf () in CPhoto of The function printf () in C
    the printf () function in the standard c library sends formatted output to a stdout.
  • time.h in CPhoto of time.h in C
    the file header named time.h in standard library c defines four variable types, two macros and various functions for date and time operations.
  • The function getenv () in CPhoto of The function getenv () in C
    char * getenv (const char * name) function searches the environment string pointed to by the name parameter and returns the value associated with that string.