I have made this program which im really certain would work, it compiles with no errors, but runs continuously after getting the name of the output file.
The program takes a loads of names each with 12 numbers, gets the name using getline, and puts the numbers into an array.
Or that's what it is meant to do, what have i missed?
#include <iostream.h>
#include <string>
#include <fstream>
using namespace std;
bool getInputFilename(char fname[])
{
ifstream fin;
cout << "Please enter the filename for input : ";
cin >> fname;
fin.open(fname, ios::nocreate);
if (!fin.is_open())
return false;
fin.close();
return true;
}
bool getOutputFilename(char fname[])
{
ofstream fout;
cout << "Please enter the filename for output : ";
cin >> fname;
fout.open(fname);
if (fout.fail())
return false;
fout.close();
return true;
}
void getInput(ifstream& fin, char name[], int marks[])
{
while(!fin.eof())
{
fin.get();
fin.getline(name, 100, '\n');
for(int j=0; j<12; j++)
{
fin >> marks[j];
}
fin.get();
}
}
void main()
{
ifstream fin;
ofstream fout;
char stname[100];
int marks[12];
char IFname[20], OFname[20];
while (!getInputFilename(IFname))
{
cout << "Invalid filename try again!\n\n";
}
while (!getOutputFilename(OFname))
{
cout << "Invalid filename try again!\n\n";
}
fout.open(OFname);
fin.open(IFname);
getInput(fin, stname, marks);
fout.close();
fin.close();
}
Code in blue is where something is wrong i believe...