Find and Replace Text Function
im working on a find and replace text function now, with not alot of luck
heres what i have so far
Code:
int replace(char *source, char search[], char replace[]) {
char *value = (char *)malloc( ( strlen(source) - strlen(search) ) + strlen(replace) );
char *start = strstr(source, search);
strncpy(value, source, *start);
printf("%s\n", value);
return 0;
}
int main() {
char temp[] = "testing a new idea";
replace(temp, "new", "WORKING");
return 0;
}
i want to look for string search in string source and copy it to a seperate string. then i want to strcat the replace and copy what was left over from string.
right now the strncpy(value, source, *start); line doesnt seem to be working. i now its a memory adress im giving it, but is there and way i can use it like a subscript?
i was think about making a function to figure out the subscript from the address and the string name, but it really cant be done. characters can repeat them self.