Wednesday 15 February 2012

C++ program from file handling. Copy text from one file and put it into other by making text of other file in upper case

C++ program from file handling. Copy text from one file and put it into other by making text of other file in upper case

// The program is :
#include <fstream.h>
#include <conio.h>
#include <process.h>
#include <ctype.h>
void main()
{
char in_char; // Input character
fstream in_obj, out_obj1;
in_obj.open("Report.TXT", ios::in); // Opens file for read mode
out_obj1.open("Finerep.txt", ios::out); // Opens file for write mode
if (!in_obj)
{
cerr << "\n\n*** That file does not exist ***\n";
exit(0); // Exit program
}
cout << "\nCopying ... \n";
in_obj.get(in_char);
in_char = toupper(in_char);
out_obj1.put(in_char);
while (in_obj.get(in_char))
{
if (in_char == '.')
{
out_obj1.put(in_char);
in_obj.get(in_char);
in_char = toupper(in_char);
out_obj1.put(in_char);
}
else
out_obj1.put(in_char);
}
in_obj.close();
out_obj1.close();
}

Step by step explanation:

1.the header file"conio.h"is used to include the function like getch and clrscr.
2.void main is also a void type function it is worked under the curley brackets.
3.while and if is a conditional statement it is used to check the condition.
4.else is also a conditional statement it is used when the while and if condition fails.

No comments:

Post a Comment