This commit is contained in:
2026-02-09 03:43:16 +01:00
parent 5082f62e59
commit d6eecf0cee
8 changed files with 143 additions and 20 deletions
+16 -14
View File
@@ -5,21 +5,20 @@ char **insert_string(char **strings_array, int *array_size, char *insert_str, in
char **rslt = malloc((*array_size + 1 )* sizeof(char *));
if(rslt == NULL) return NULL;
int index_clc = 0;
int index_clc2 = 0;
//char *temp;
while (index_clc < *array_size){
while (index_clc < *array_size + 1){
if (index_clc == index){
*(rslt + index_clc) = insert_str;
index_clc ++;
}
if (index_clc == index) *(rslt + index_clc) = insert_str;
else{
*(rslt + index_clc) = *(strings_array + index_clc);
}
*(rslt + index_clc) = *(strings_array + index_clc2);
index_clc2 ++;
}
/*
if (index_clc >= index){
@@ -33,20 +32,23 @@ char **insert_string(char **strings_array, int *array_size, char *insert_str, in
//*(strings_array + index) = insert_str;
//free(temp);
*array_size = *array_size + 1;
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;
while (index < 6){
printf("%s", *(rslt + index));
index ++;
if(rslt != NULL){
for (int i = 0; i < ted; i ++) printf("%s",rslt[i]);
}
printf("\n");
free (rslt);
}
*/