Hi,
I wrote a simple on-file directory lister. It works, but I have to press Ignore in a block damage error messagebox everytime I tun it. Any idea? Thanks in advance.

#include <windows.h> 
#include <iostream> 
#include <string.h>
#include <string>
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main()
{
    HANDLE hFind;
    WIN32_FIND_DATA FindData;

   char * curWorkDir=new char[MAX_PATH];

   if( (curWorkDir = _getcwd( NULL, 0 )) == NULL )
      perror( "_getcwd error" );


	FILE * out = fopen("ListFile.txt", "w");
	sprintf(curWorkDir,"%s\\*.*",curWorkDir);
	cout<<curWorkDir<<endl;
    hFind = FindFirstFile(curWorkDir, &FindData);
    fprintf(out, FindData.cFileName);


    while (FindNextFile(hFind, &FindData))
    {
        fprintf(out, FindData.cFileName);
		fputc('\n', out);
    }


    FindClose(hFind);
	fclose(out);

	delete curWorkDir;

	cout<<"ListFile generated\n";

    return 0;
}

If this is c++ why don't you just use fstream instead of FILE*.

>> fprintf(out, FindData.cFileName);
>> fputc('\n', out);

why not just this: fprintf(out, "%s\n", FindData.cFileName); >>I have to press Ignore in a block damage error messagebox everytime I tun it
What? I have no idea what you are talking about.

It's a typo, sorry I meant "everytime I run it". It's a Debug error ("Damage after normal block #45")

What? I have no idea what you are talking about.

He's talking about the C++ fstream class(es)

Edit:: Sorry I misunderstood the OP's post (he was actually quoting but I didn't notice that) :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.