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 85 views
85 views asked Jun 10, 2025 by avibootz
1 answer 132 views
1 answer 128 views
2 answers 213 views
213 views asked Jan 7, 2024 by avibootz
1 answer 121 views
1 answer 126 views
126 views asked Dec 25, 2022 by avibootz
1 answer 110 views
110 views asked Dec 20, 2022 by avibootz
...