C++ program to copy one file to anothere file

AIM
A program to copy one file to another file and convert the lower case characters to upper case characters.

ALGORITHM

1) Start the process
2) Create the input file and out put file.
3) Get the input file name to fname1.
4) Get the output file name to fname2.
5) Open the infile(fanme1)
6) Check if infile.fail()
a) True:
i) Execute error conversion
ii) exit
7) open the outfile(fanme2)
8) check if outfile.fail()
a) repeat step(6:a)
9) check while infile.eof()
a) True:
i) Ch?(char)infile.get()
10) Close both files
11) Stop the process.

PROGRAM :

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<ctype.h>
#include<fstream.h>
 
void main( )
{
	ofstream outfile;
	ifstream  infile;
	char fname1[10],fname2[20];
	char ch,uch;
	clrscr( );
	cout<<"Enter a file name to be copied ";
	cin>> fname1;
	cout<<"Enter new file name";
	cin>>fname2;
	infile.open(fname1);
 
if( infile.fail( ) )
	{
		cerr<< " No such a file Exit";
		getch();
		exit(1);
	}
	outfile.open( fname2);
		if(outfile.fail( ))
		{
			cerr<<"Unable to create a file";
			getch();
			exit(1);
		}
	while( !infile.eof( ) )
	{
		ch = (char) infile.get( );
		uch = toupper(ch);
		outfile.put(uch);
	}
	infile.close( );
	outfile.close( );
	getch( );
}

OUTPUT:

Enter a file name to be copied.
C:\text1.txt
Enter new file name
D:\new.txt

Input file
Asbcdefghijklmnopqrstuvwxyz
Output file
ASBCDEFGHIJKLMNOPQRSTUVWXYZ

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

5 thoughts on “C++ program to copy one file to anothere file

  1. Hi all, how to call a program from another program and how to execute
    more than one function at a time.
    I am new to c++ concepts, so please any one help me by providing
    code….

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in