Using strrchr to search for the last occurrence of the specified character in a string. - C++ Data Type

C++ examples for Data Type:char array

Description

Using strrchr to search for the last occurrence of the specified character in a string.

Demo Code

#include <iostream> 
#include <cstring> // strrchr prototype 
using namespace std; 

int main() /*from w  w w .j  a v  a  2s . com*/
{ 
    const char *string1 = "this is a test, zoo zebras zill"; 
    char c = 'z'; 

    cout << "string1 = " << string1 << "\n" << endl; 
    cout << "The remainder of string1 beginning with the\n" 
        << "last occurrence of character '" 
        << c << "' is: \"" << strrchr( string1, c ) << '\"' << endl; 
    
    
}

Result


Related Tutorials