Description Searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str. The terminating null character is considered to be part of the string. Returns a pointer pointing to the last matching character, or null if no match was found.
Asked
Active
Viewed 360 times
-9
-
*Image with examples is posted* No it is not. And please don't post pictures of code or other text. – Gerhardh May 25 '22 at 09:47
-
1Please also read [How to ask](https://stackoverflow.com/help/how-to-ask) and [How do I ask and answer homework questions?](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) Just dumping a task is not the way SO works. Show what you have tried so far. Tell us where **specifically** you are stuck. We can solve specific problems but we cannot replace learning basic stuff. – Gerhardh May 25 '22 at 09:49
-
I have just started learning C language, and also I do not have any programming background , and posting my first question in Stackoverflow I have been trying to solve this exercise for 2 days, but it sucks – Azizbek Kamolov May 25 '22 at 10:00
-
Also don't post pictures of text. Post text as properly formatted text. – Jabberwocky May 25 '22 at 10:01
1 Answers
1
The function strrchr()
is very simple to write in C: it suffices to iterate on the string, remembering the last position where the character was seen...
#include <string.h>
/* 7.24.5.5 The strrchr function */
char *strrchr(const char *s, int c) {
const char *p = NULL;
for (;;) {
if (*s == (char)c)
p = s;
if (*s++ == '\0')
return (char *)p;
}
}

chqrlie
- 131,814
- 10
- 121
- 189