C Programming - Library Functions - Discussion

Discussion Forum : Library Functions - General Questions (Q.No. 3)
3.
Which standard library function will you use to find the last occurance of a character in a string in C?
strnchar()
strchar()
strrchar()
strrchr()
Answer: Option
Explanation:

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

Example:


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

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.

Discussion:
18 comments Page 2 of 2.

Kiran said:   1 decade ago
Excellent srikanth.

Mayur22kar said:   4 years ago
Thanks @Srikanth.

Prateek said:   8 years ago
Thanks @Srikanth.

Rajes said:   9 years ago
Thanks @Srikanth.

RENU GURPREET said:   1 decade ago
Thanks @Srikanth.

Pruthvi said:   1 decade ago
Why -str is used?

Ravi said:   1 decade ago
Thanks srikanth.

Mostafa Yasin said:   8 years ago
Thanks @Ashish.


Post your comments here:

Your comments will be displayed after verification.