Need help with text reversing progam..
i'm trying to write a program that will take the contents of one file and completely reverse it and put it into a new file... what i have currently takes each word and reverses it then puts it into a file... for example:
input: the dog was big
current program: eht god saw gib
what i want: gib saw god eht
i had tried to use getline before but i could get it to work..
heres my code so far:
Code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void main()
{
char filenameOld[30];
char filenameNew[30];
string text;
int i;
cout << "What file do you want to backwardsify?\n";
cin.getline(filenameOld, 30, '\n');
cout << "What do you want the new file to be called?\n";
cin.getline(filenameNew, 30, '\n');
ifstream a_file(filenameOld);
ofstream b_file(filenameNew);
do
{
a_file>>text;
for (i=text.length(); i>=0; i--)
{
b_file<<text[i];
}
b_file<<" ";
cout<<".";
}
while (a_file.eof()!=1);
cout<<"DONE\n";
a_file.close();
b_file.close();
}
any suggestions?