A program that replaces all s1's with s2 in a string : <p>I found this program that replaces all s1's with s2 in a string and i don't understant the sequence<br>
  int i = strstr(s, s1) - s ?</p>

<pre><code>enter code here
#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;

char *my_replace(char *s, char *s1, char *s2)
{

    char *aux = (char *) malloc((sizeof(s) - sizeof(s1)) + sizeof(s2) + 1);
    int i = strstr(s, s1) - s, j = strlen(s1);
    strncpy(aux, s, i);
    strcat(aux, s2);
    strncat(aux, (s + i + j), (strlen(s) - i - j));
    return aux;
 }


 int main()
 {
    char *s, *s1, *s2;
    s = (char*)malloc(10);
    s1 = (char*)malloc(10);
    s2 = (char*)malloc(10);
    char *aux;
    scanf("%s%s%s", s, s1, s2);
    aux = my_replace(s, s1, s2);
    printf("%s\n", aux);
    return 0;
   }
</code></pre>
