How to implement the strrstr function in C

1 Answer

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

char* strrstr(const char* haystack, const char* needle) {
    char* result = NULL;
    char* current = strstr(haystack, needle);
    
    while (current) {
        result = current;
        current = strstr(current + 1, needle);
    }
    
    return result;
}

int main() {
    const char* str = "C#:C C++:Java:C: Python";
    
    char* p = strrstr(str, "C");
    
    printf("%s\n", p);

    return 0;
}



/*
run:

C: Python

*/

 



answered Aug 2, 2024 by avibootz

Related questions

1 answer 89 views
89 views asked Jun 10, 2025 by avibootz
1 answer 140 views
1 answer 139 views
2 answers 232 views
232 views asked Jan 7, 2024 by avibootz
1 answer 131 views
1 answer 138 views
138 views asked Dec 25, 2022 by avibootz
1 answer 119 views
119 views asked Dec 20, 2022 by avibootz
...