07-06-2003, 09:37 AM
I don't really have a preference on either one of the methods. They both take up 12 lines of code.
I am really liking C++ more and more. I do have another question. If I have an array of strings how could I figure out how many different strings are in it?
The reason I need to know is because I pass a char **files to a function that mallocs everything with each string in the array the length of the biggest filename. So when I get back to the function that had **files in it, I don't know it's dimensions (how long the longest string is, and how many strings there are in the array).
I know that using a reference pointer passes through the function parameters for the number of files and biggest filename would work, but I kinda wanted something cleaner.
also, when you free an array of strings, is it nessacery to free each individual entry in the array, or could you just free the whole thing at once?
like this
or like this
I am really liking C++ more and more. I do have another question. If I have an array of strings how could I figure out how many different strings are in it?
The reason I need to know is because I pass a char **files to a function that mallocs everything with each string in the array the length of the biggest filename. So when I get back to the function that had **files in it, I don't know it's dimensions (how long the longest string is, and how many strings there are in the array).
I know that using a reference pointer passes through the function parameters for the number of files and biggest filename would work, but I kinda wanted something cleaner.
also, when you free an array of strings, is it nessacery to free each individual entry in the array, or could you just free the whole thing at once?
like this
Code:
for (i = 0; i < num_files; i++) free(files[i]);
free(files);
Code:
free(files);
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Max:"Out the window, Sam. There's nobody but strangers out there."