Hi,
I have to write a program which makes changes and writes to a different text file. The point at which I am stuck is that I am unable to add the value 10 to ASCII value of each of the first 6 characters in the file.
Can someone tell em where I am going wrong?
//
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
void changes(ifstream& in_stream, ofstream& out_stream);
int main()
{
ifstream fin;
ofstream fout;
cout << "Begin editing files.\n";
fin.open("TextIn.txt");
if (fin.fail( ))
{
cout << "Input file opening failed.\n";
system ("pause");
exit(1);
}
fout.open("TextOut.txt");
if (fout.fail( ))
{
cout << "Output file opening failed.\n";
system ("pause");
exit(1);
}
changes(fin, fout);//Making changes to file
fin.close( );
fout.close( );
cout << "End of editing files.\n";
system("pause");
return 0;
}
// Program to change underscore to spaces, uppercase to lowercase
void changes(ifstream& in_stream, ofstream& out_stream)
{
char next;
in_stream.get(next);
while (! in_stream.eof( ))
{
//Changing to lowercase
if (next >= 'A' && next <= 'Z')
next += 'a' - 'A';
//Changing underscores to spaces
if (next == '_')
out_stream << " ";
else
out_stream.put(next);
// Adding the value 10 to each character
for(char next=0; next<=6; next++)
{
next=+10;
}
//Getting the next character
in_stream.get(next);
}
}