Co napr. takto?
Kód:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *strcrep(char *string, char this, char *that); /* replaces first occurrence of 'this' in 'string' with 'that' */
int main() {
char *output;
output = strcrep("ABCD*ABCD", '*', "Palo");
printf("%s",output);
free(output);
return 0;
}
char *strcrep(char *string, char this, char *that) {
int output_len, tmp_i;
char *output, *tmp_c;
output_len = strlen(string);
output_len += strlen(that);
output = (char *)malloc(output_len*sizeof(char));
if (output == NULL)
return NULL;
tmp_c = strchr(string, this);
if (tmp_c == NULL)
return NULL;
tmp_i = tmp_c - string;
strncpy(output, string, tmp_i);
strcat(output, that);
strcat(output, tmp_c+1);
return output;
}