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

// Function to find the first occurrence of 'find' in 'str'
// Returns the index of the first character of 'find' in 'str'
// Returns -1 if 'find' is not found in 'str'
int strstrr(char *str, char *find) {
    char *ffind = find;
    int index = 0;

    while (*str) {
        char *sstr = str;
        while (*sstr && *sstr == *ffind) {
            sstr++;
            ffind++;
        }
        if (*ffind == '\0') {
            return index;
        }
        str++;
        index++;
    }
    return -1;
}

int main() {
    char str[] = "my name is adarsh";
    char find[] = "is";
    char replace[] = "was";

    // Find the index of the first occurrence of 'find' in 'str'
    int ind = strstrr(str, find);

    // Print the index
    printf("%d\n", ind);

    // Create a new string 'new' to store the result
    char new[30] = {0};

    // Copy the characters from the beginning of 'str' up to the index
    strncat(new, str, ind);

    // Append the replacement string 'replace'
    strcat(new, replace);

    // Append the characters in 'str' after the replaced substring
    strcat(new, str + ind + strlen(find));

    // Print the original string with the replaced substring
    printf("%s\n", str);

    // Print the new string after replacement
    printf("%s\n", new);

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: