Home / C Programming / Library Functions :: Discussion

Discussion :: Library Functions

  1. Which standard library function will you use to find the last occurance of a character in a string in C?

  2. A.

    strnchar()

    B.

    strchar()

    C.

    strrchar()

    D.

    strrchr()

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    strrchr() returns a pointer to the last occurrence of character in a string.

    Example:

     #include  
     #include  
    
      int main() 
      {     
           char str[30] = "12345678910111213";   
           printf("The last position of '2' is %d.\n",     
                   strrchr(str, '2') - str);     
           return 0;
       } 
    

    Output: The last position of '2' is 14.

     


Be The First To Comment