Let's say I have 11 files with extension ".exe" files in the folder c:/.
And I want to create 11 pointers of type char*, each of this pointer contains the file name of the .exe file. So, we have 11 pointers - 11 file names.
But the output is what really confuses me (see below).
Why do I have correct result while I'm inside the while-loop, but then when I'm checking the same values of the pointers outside the loop - it's just empty?
I have no idea how to fix that...
Any help will be appreciated.
Thank you!
readir() might reuse the same dirent object each time it's called so if you want to hang on to the filenames you will have to copy them elsewhere.
Instead of using an array of pointers why don't you use a vector of strings (std::vector<std::string>)? I think that would make life much easier for you.