Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* myreplaceall(char* str, char* suf1, char* suf2) {
- char* res = (char*)malloc(sizeof(char*));
- res[0] = '\0';
- int i = 0; int i2 = 0; int j = 0;
- while (i < strlen(str)) {
- while ((str[i+j] == suf1[0+j]) & (j != strlen(suf1))) j++;
- if (j == strlen(suf1)){
- res = realloc(res, i2 + strlen(suf2));
- for (int k = 0; k < strlen(suf2); k++) res[i2 + k] = suf2[0 + k];
- i = i + strlen(suf1);
- i2 = i2 + strlen(suf2);
- }
- else {
- res = realloc(res, i2 + 1);
- res[i2] = str[i];
- i++; i2++;
- }
- j = 0;
- }
- res[i2] = '\0';
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement