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
5 Antworten
0
Is that the example program that has been given to you?
0
Ani Jona 🕊 wdym
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).
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.
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.