Advertisement

Appending the contents of one file to another

Started by January 03, 2003 07:41 PM
0 comments, last by sundaythedog 21 years, 10 months ago
I''m trying to take the contents of one (small) file and add it to another (big) file. I tried the following code, but it gives me an error "effectsadder.exe has encountered a problem and needs to close...Send or Don''t Send error report to M$". Her''es the code:
  
#include <stdio.h>
#include <stdlib.h>


main()
{
	FILE *seffect;		//single effect to be appended to larger multiple effect file (meffect)

	FILE *meffect;		//multiple effect file to have seffect apppended to


	char effect;			//contents 

	char seffectadd[]="c:/cfs3 progs/seffect.xml";		//address to seffect

	char meffectadd[]="c:/Documents and Settings/Sean Grapevine/My Documents/effects.xml";		//address to meffect

	
	seffect = fopen(seffectadd, "r");
	
		
		while(effect!=EOF)		//while EOF is not reached get char and store it in effect

		{
			putchar(effect);
			effect = fgetc(seffect);
		}

	printf("%s", effect);		//prints contents of single effect file to screen

	fclose(seffect);			//closes single effect file

	meffect = fopen(meffectadd, "a");		//open multiple effect file for appending

	fprintf(meffect, "%s", effect);			//

	fclose(meffect);
	
	return 0;
}
  
It will throw up a DOS console with the contents of the file and then the error message will come up. After I click "don''t send", the DOS console still stays up giving me the normal "Press a button to conitnue" message. Any idea what''s wrong? I''m using XP Home. The Light shine on you
The Light shine on you

  #include <fstream>#include <string>using namespace std;int main(){   string src = "c:/cfs3 progs/seffect.xml";   string dst = "c:/Documents and Settings/Sean Grapevine/My Documents/effects.xml";   ifstream infile( src.c_str() );   ofstream outfile( dst.c_str(), ios::app );   outfile << infile.rdbuf();}  


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement