This commit is contained in:
2026-02-05 18:39:33 +01:00
parent b400d34574
commit 5082f62e59
2 changed files with 40 additions and 3 deletions
+42 -5
View File
@@ -4,12 +4,49 @@
char **insert_string(char **strings_array, int *array_size, char *insert_str, int index){ char **insert_string(char **strings_array, int *array_size, char *insert_str, int index){
char **rslt = malloc(array_size + 1 * sizeof(char)); char **rslt = malloc((*array_size + 1 )* sizeof(char *));
int index_clc = 0;
//char *temp;
while (index_clc < *array_size){
if (index_clc == index){
*(rslt + index_clc) = insert_str;
index_clc ++;
}
else{
*(rslt + index_clc) = *(strings_array + index_clc);
}
/*
if (index_clc >= index){
temp = *(strings_array + index_clc);
*(rslt + index + 1) = *(strings_array + index);
}*/
index_clc ++;
}
//*(rslt + index_clc) = temp;
//*(strings_array + index) = insert_str;
//free(temp);
return rslt;
}
int main(){
char *tests[] = {"This", "is", "a", "long", "example"};
char *ins = "very";
int ted = 5;
char **rslt = insert_string(tests, &ted, ins ,3);
int index = 0; int index = 0;
while (*(strings_array + index)){ while (index < 6){
printf("%s", *(rslt + index));
index ++;
}
free (rslt);
} }
}
BIN
View File
Binary file not shown.