Click here to Skip to main content
15,843,962 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to read and write to a BINARY file? Pin
David Crow29-Oct-09 18:01
David Crow29-Oct-09 18:01 
AnswerRe: How to read and write to a BINARY file? Pin
Adam Roderick J29-Oct-09 18:58
Adam Roderick J29-Oct-09 18:58 
QuestionA General Problem Pin
WindowsVsLinux29-Oct-09 9:49
WindowsVsLinux29-Oct-09 9:49 
AnswerRe: A General Problem Pin
«_Superman_»29-Oct-09 10:04
professional«_Superman_»29-Oct-09 10:04 
GeneralRe: A General Problem Pin
WindowsVsLinux29-Oct-09 19:03
WindowsVsLinux29-Oct-09 19:03 
QuestionRe: A General Problem Pin
David Crow29-Oct-09 10:30
David Crow29-Oct-09 10:30 
AnswerRe: A General Problem Pin
WindowsVsLinux29-Oct-09 19:05
WindowsVsLinux29-Oct-09 19:05 
AnswerRe: A General Problem Pin
enhzflep29-Oct-09 10:36
enhzflep29-Oct-09 10:36 
Perhaps «_Superman_» overlooked the difference between c and c++ when it came to dynamically sized array declarations - they work just fine here too.


Um, this is really very easy.
You need to declare somewhere to hold a string.
After each new filename has been retrieved it's tacked onto the end of the existing string
When the loop's over the string is printed.

I can think of at least 3 ways around this mountain, though (surprise, surprise) went for the easiest/quickest/dodgiest (is that even a word?) way.


1. Declare a new var in main and initialize to 4096 times "\0" (since I'm testing in C:\ and I know there to be under 4kb worth of file/folder names there)

char finalString[4096];



2. Add to it each time through the loop

while (FindNextFile(hFind, &FindFileData) != 0)
{
    strcat(finalString, FindFileData.cFileName);
    strcat(finalString, "\n");
}




3. Print it out

printf("%s\n", finalString);




The other two ways that come to mind are:

1. Dynamically resizing the memory used to hold the final string.
2. Getting a count of the number of dir-entries, then creating an array of char* with that many entries. You then alloctae some memory, point dirEntryArray[curEntryNum] at this memory, and make sure you copy the current filename into said mem.

You can probably see why I went for the 'coding-horrors' way. Sigh | :sigh:


EDIT: ah crap! See, that's why David is an MVP, and I'm not. Sniff | :^)
GeneralRe: A General Problem Pin
WindowsVsLinux29-Oct-09 19:08
WindowsVsLinux29-Oct-09 19:08 
GeneralRe: A General Problem Pin
Adam Roderick J29-Oct-09 19:21
Adam Roderick J29-Oct-09 19:21 
Questionpointer and switch Pin
kbury29-Oct-09 9:18
kbury29-Oct-09 9:18 
AnswerRe: pointer and switch Pin
«_Superman_»29-Oct-09 9:21
professional«_Superman_»29-Oct-09 9:21 
GeneralRe: pointer and switch Pin
kbury29-Oct-09 9:24
kbury29-Oct-09 9:24 
AnswerRe: pointer and switch Pin
CPallini29-Oct-09 11:58
mveCPallini29-Oct-09 11:58 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 3:31
kbury30-Oct-09 3:31 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 3:52
mveCPallini30-Oct-09 3:52 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 10:37
kbury30-Oct-09 10:37 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 11:43
mveCPallini30-Oct-09 11:43 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 11:57
kbury30-Oct-09 11:57 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 12:00
mveCPallini30-Oct-09 12:00 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 12:05
kbury30-Oct-09 12:05 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 12:06
kbury30-Oct-09 12:06 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 12:23
mveCPallini30-Oct-09 12:23 
Questionhow to fit the result application from WinExec() in a splitter window? Pin
Member 333413529-Oct-09 9:01
Member 333413529-Oct-09 9:01 
AnswerRe: how to fit the result application from WinExec() in a splitter window? Pin
«_Superman_»29-Oct-09 9:13
professional«_Superman_»29-Oct-09 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.