1. Write a C++ program ask to the user to enter file name to encrypt its content.
Vanmarga files
Answers
Please tell question properly
Program:
#include<iostream>
#include<fstream>
#include<stdio.h>
using namespace std;
int main()
{
char name[100], ch;
fstream file, temp;
cout<<"Enter the file name (with the extension .txt): ";
gets(name);
file.open(name, fstream::in);
if(!file)
{
cout<<"\nError in opening the file you want";
return 0;
}
temp.open("temporary.txt", fstream::out);
if(!temp)
{
cout<<"\nError in opening or creating the temporary file";
return 0;
}
while(file>>ch)
{
ch = ch+10;
temp<<ch;
}
file.close();
temp.close();
file.open(name, fstream::out);
if(!file)
{
cout<<"\nError in opening the file you want";
return 0;
}
temp.open("temporary.txt", fstream::in);
if(!temp)
{
cout<<"\nError in opening the temporary file";
return 0;
}
while(temp>>ch)
file<<ch;
file.close();
temp.close();
cout<<"\nFile "<<name<<" Encrypted Successfully!";
cout<<endl;
return 0;
}