strrchr - C string.h

C examples for string.h:strrchr

Type

function

From

<cstring> 
<string.h>

Description

Locate last occurrence of character in string

Prototype

const char * strrchr ( const char * str, int character );
      char * strrchr (       char * str, int character );

Parameters

Parameter Description
str C string.
character Character to be located.

Return Value

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

Demo Code


#include <stdio.h>
#include <string.h>

int main ()/*from www. j  a  v  a2  s.com*/
{
  char str[] = "This is a sample string";
  char * pch;
  pch=strrchr(str,'s');
  printf ("Last occurrence of 's' found at %d \n",pch-str+1);
  return 0;
}

Related Tutorials