Hi,
I'm trying to encrypt a simple .txt file. What I want to do is is described by the function definitions. I want to change all my characters in the .txt file to lower case and then convert any digits found into *. I've done this before in the past, but I wasn't using a file. My output file is not receiving the changes.
Any help would be appreciated.
Brent
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;
void GetLetter(ifstream& in_stream, ofstream& out_stream);
void UnderscoreToSpace(ifstream& in_stream, ofstream& out_stream); //needs the input file & output file; & means file address - call by reference.
void ChangeToLowerCase(ifstream& in_stream1, ofstream& out_stream1);
void NumToSymbol(ifstream& in_stream2, ofstream& out_stream2);
int main( )
{
// Declarations
ifstream fin; // input file
ofstream fout; // output file
ifstream fin1;
ofstream fout1;
ifstream fin2;
ofstream fout2;
ifstream fin0;
ofstream fout0;
cout << "Begin editing files.\n"; // Declares the file is working
// Attach the internal file(fin.open) to the external file ( cad.dat)
fin.open("C:\\Documents and Settings\\Brent\\My Documents\\textIn.txt"); //(directory - file name)
if (fin.fail( )) // if the data doesn't load
{
cout << "Input file opening failed.\n";
exit(1);
}
// open output file
fout.open("C:\\Documents and Settings\\Brent\\My Documents\\textOut.txt"); //(directory - file name)
if (fout.fail( ))// if the data doesn't load
{
cout << "Output file opening failed.\n";
exit(1);
}
GetLetter(fin0, fout0);
UnderscoreToSpace(fin, fout); //function to process the input & output file - file pointer
ChangeToLowerCase(fin1, fout1);
NumToSymbol(fin2, fout2);
fin.close( );
fout.close( );
cout << "\n\nEnd of editing files.\n";
system("pause");
return 0;
}
void GetLetter(ifstream& in_stream0, ofstream& out_stream0)// function header or definition
{
char next; // char = character data; 1 byte variable
in_stream0.get(next); // get function 'gets the next character in line; priming read
while (! in_stream0.eof( ))// eof = end of file; while (! or not) we don't have an end of file marker
for(int n=0; n<6; n++)
{
next = toupper(next +10);
cout <<next<<endl;
}
}
void UnderscoreToSpace(ifstream& in_stream, ofstream& out_stream)// function header or definition
{
char next; // char = character data; 1 byte variable
in_stream.get(next); // get function 'gets the next character in line; priming read
while (! in_stream.eof( ))// eof = end of file; while (! or not) we don't have an end of file marker
{
if (next == '_')
out_stream << " "; // file out while cout is monitor out
else
out_stream.put(next);
in_stream.get(next);
}
}
void ChangeToLowerCase(ifstream& in_stream1, ofstream& out_stream1)
{
char next;
in_stream1.get(next);
while (! in_stream1.eof( ))
{
if(isupper(next))
out_stream1 << static_cast<char>(tolower(next));
else
out_stream1.put(next);
in_stream1.get(next);
}
}
void NumToSymbol(ifstream& in_stream2, ofstream& out_stream2)
{
char next;
in_stream2.get(next);
while (! in_stream2.eof( ))
{
if(isdigit(next))
out_stream2 << '*';
else
out_stream2.put(next);
in_stream2.get(next);
}
}