Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text file output

Status
Not open for further replies.

nhungr

Programmer
Jan 31, 2005
26
CA
Hello.

I have a C++ function that ouputs a set of data text files. I pass the directory path of where I want the files to be stored to the function through a BSTR variable. I then need the function to take this path string and append it to the front of the name of each text file. For example:

DirPath = "C:\MyDocs\NewFolder"
Filename1 = "Textfile1.txt"
Filename2 = "Textfile2.txt"

Add the above to give:
Filename1 = "C:\MyDocs\NewFolder\Textfile1.txt"
Filename2 = "C:\MyDocs\NewFolder\Textfile2.txt"

Then output data into each of these files using ofstream.

Here is the code I have so far, however, nothing gets saved in the appropriate folder at all, and I don't know why. Where am I going wrong? It must be a pointer problem or something. Any help would be greatly appreciated. Thanks.
Code:
	LPSTR DirPath;

	void MyFunction(BSTR DirPathArg)
	{
		DirPath = (LPSTR)DirPathArg;	
		OutputFiles();
	}

	void OutputFiles()
	{
		char filename1=*DirPath;
		char *buffer1=&filename1;
		strcat(buffer1,"\\Textfile1.txt");
	
		char filename2=*DirPath;
		char *buffer2=&filename2;
		strcat(buffer2,"\\Textfile2.txt");

		ofstream outfile1(buffer1);
		outfile1<< "Data1";
		[b]outfile1<< ... etc ...[/b]

		ofstream outfile2(buffer2);
		outfile2<< "Data2";
		[b]outfile2<< ... etc ...[/b]
	}
 
Ok, never mind. I got it. Rather silly mistake.

ie.
Code:
char filename1[MAXCHARS];
strcpy(filename1,DirPath);
strcat(filename1,"\\Textfile1.txt");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top