Write a C++ program to copy a file into another file using following rules:
i) convert lowercase alphabets to uppercase alphabets and vice versa.
ii) copy other characters as it is.
#include<conio.h>
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <cmath>
#include<dos.h>
#include <bits/stdc++.h>
#include<vector>
using namespace std;
/*
Write a C++ program to copy a file into another file using following rules:
i) convert lowercase alphabets to uppercase alphabets and vice versa.
ii) copy other characters as it is.
*/
main(void)
{
ifstream infile,outfile;
char x,y;
string Name1 = "H:\\Test_1.txt";
string Name2 = "H:\\Test_2.txt";
infile.open(Name1.c_str());
outfile.open(Name2.c_str());
if (!infile)
{
cout << "Unable to open file: "<<Name1;
exit(1); // terminate with error
}
else
{
cout<<"\nContents of File_1.txt: ";
while(infile >> x)
{
if(x>="a" && x <="z") {y = toupper(x); outfile<<y;}
if(x>="A" && x <="Z") {y = tolower(x); outfile<<y;}
}
infile.close();
outfile.close();
}
return(0);
}
Comments
Leave a comment