C++ Program to Copy Text from One File to Another

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<io.h>

void main()
{
	clrscr();
	FILE *in, *og;
	in= fopen("C:\\am\\ankur.txt","r");
	og= fopen("D:\\am\\mhatre.txt","w");
	
	int end = -1;

	char ch = fgetc(in); //read first char

	if (ch == end)
	{
		cout<<"Error in opening file";
	}
	else
	{
		fputc(ch,og);
		
		/*Reading rest file*/

		while(!feof(in))
		{
			char ch=fgetc(in);
			if( ch!= end)
			{
				fputc(ch,og);
			}
		}
		cout<<"File copied";
	}

	fclose(in);
	fclose(og);
	getch();
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.