I have an array of strings, and I am trying to malloc more space for one of those strings so I can change the value of the string.
int catenate_strings (char** arr, int index1, int index2) {
char *new_string;
new_string = malloc(1000*sizeof(char));
if (new_string == NULL) {
printf("\nError allocating memory\n");
}
strcpy(new_string, arr[index1]);
strcat(new_string, arr[index2]);
arr[index1] = new_string;
}
However when I run my code, it will work for some instances, but in others it will duplicate the string at index1 and put it at index1 + 1 as well.