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 92 views
92 views asked Jun 10, 2025 by avibootz
1 answer 143 views
1 answer 144 views
2 answers 240 views
240 views asked Jan 7, 2024 by avibootz
1 answer 135 views
1 answer 141 views
141 views asked Dec 25, 2022 by avibootz
1 answer 121 views
121 views asked Dec 20, 2022 by avibootz
...