I have an array in C, let's suppose it's
**arr = malloc(100 * sizeof(char*));
through some function, I populate this array in such a way that it ends up being
arr = {"first", "second", "third", "fourth", ... "tenth"};
Now, if I want to populate it anew, so that it's
arr = {"1st", "2nd", "3rd"}; //Desired outcome
it instead is shown as
arr = {"1st", "2nd", "3rd", "fourth", "fifth", ... "tenth"}; //Actual outcome
I'm certain my code is wrong, and my function for populating it from empty is fine, but I just want to find a way to wipe it. I tried free(), but I either used it wrong or that's not what I should be using.
Do any of you have a function that can not just set a string to "\0", but completely eradicate it?
To all that commented and answered, thank you.
What I was doing was using text files, strtok, and strdup to read words from a file into a char double pointer. I don't want any more than 5000 words stored in the "array", even if my file is 5001+ words.
I did this. I successfully populated the memory with the strings from the file. But if I changed my mind and tried to populate the memory with a smaller file (~30 words), it would change the first 30 and leave the remaining 4970 as they were, when I wanted them not to exist.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)