Here is the code:
// All this has to do is take the "names.txt" file, and send it to "backwards.txt"
// in reverse order, as an array. No idea why its not working, sent all necessary files with it.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <ctime>
using namespace std;
const int listofnames = 350; // This is the number of spaces in the array.
int getData(ifstream &fin, int array[]); // Here is the function that finds each piece of the array.
//string getData(ifstream &fin, string array[]); This is what it SHOULD look like.
void outputData(ofstream &fout, int array[], int numNames); // This is the output function.
//void outputData(ofstream &fout, string array[], int numNames) Also what this one should look like
//Please note, I'm only guessing right now as to what everything should be.
int main()
{
ifstream fin;
ofstream fout;
fin.open("names.txt"); // I need to use "names.txt", to display each name as apart of the array.
//fin.open("numbers.txt");
fout.open("backwards.txt");
if(fin.fail())
{
cerr << "Failed to open Input File, program terminated\n";
exit(2);
}
if(fout.fail())
{
cerr << "Failed to open Output File, program terminated\n";
exit(3);
}
int array[listofnames];
int numNames=getData(fin, array);
outputData(fout, array, numNames);
fin.close();
fout.close();
return 0;
}
int getData(ifstream &fin, int array[]) // Here, being an int, it takes "i" and uses it as the variable to count each block of the array. See next.
{
int i=0;
while(i<listofnames && fin >> array[i])
i++;
return i;
}
//string getData(ifstream &fin, string array[]) // This is the non-functional string version
//{
// int i=0;
// while(i<listofnames && fin >> array[i])
// i++;
//
// return i;
//}
void outputData(ofstream &fout, int array[], int numNames) // This function (in int form) sends the output.
{
for(int i=0;i<numNames;i++)
fout << array[i] << endl;
cout << "Did it work?\n";
}
//void outputData(ofstream &fout, string array[], int numNames) // This function (in string form) sends the output.
//{
// for(int i=0;i<numNames;i++)
// fout << array[i] << endl;
// cout << "Did it work?\n";
//} For some reason this doesn't work.
All this has to do is take the strings in "names.txt", and place them in reverse order. Nothing I've tried has worked, and the closest I've gotten is placed in the "//" fields.
Can anyone help? All I really need to know is how to make this coding work for a string instead of a int. I cannot use anything else, rules are rules.