How to add an array of strings to a new string in C?

How to add an array of strings to a new string in C?
April 3rd 20 at 18:47
1 answer
April 3rd 20 at 18:49
1.To allocate a new array larger by 1 element than the former;
2.copy to the beginning of the old array;
3.delete the old array.
4.the last element to assign a pointer to a new string
The first 3 points performs a realloc().

If the operation add a new item in the array is regular, then it is worth working on further. Usually in such cases is not isolated to 1 element more, such as 2 times more. This gives rise to additional requirements of storing the number of employed elements, number of elements, etc.
Operation of dynamic memory allocation is quite an expensive, so you should minimize it.

Find more questions by tags C