0

Iā€™m confused on how to add strings to a dynamically array in c

Iā€™m confused on that part. The hint that I got from the assignment is the followingā€ This is one way to add things to a dynamically allocated array. Every time we add something, we make a new version that is one location larger and destroy the original. Here is how this is used in a programā€ I created a copy but donā€™t know how to add the string into it. https://code.sololearn.com/cPWHiIQq7kXy/?ref=app

26th May 2022, 3:57 AM
Skadoosg
5 Answers
0
Is that the example program that has been given to you?
26th May 2022, 5:36 AM
Ani Jona šŸ•Š
Ani Jona šŸ•Š - avatar
26th May 2022, 5:40 AM
Skadoosg
0
"Here is how this is used in a program". That means this is an example someone wrote. "[I] don't know how to add the string to it". This indicates that you wrote something. I try to understand which part of the program we are concerned with right know. And if we are talking about understanding someone else's code or about implementing an assignment (e.g. from a textbook).
26th May 2022, 5:46 AM
Ani Jona šŸ•Š
Ani Jona šŸ•Š - avatar
0
Ani Jona šŸ•Š oh no it my code i just have hard time on the add_string function where i dont know how to add the new word to an array.
26th May 2022, 2:39 PM
Skadoosg
0
When adding a new string you need to allocate twice. Once to extend the array of strings, and a second to hold the string you want to duplicate. At the moment you are only allocating for the second but threat it as though you did the first.
27th May 2022, 8:07 AM
Ani Jona šŸ•Š
Ani Jona šŸ•Š - avatar