I keep getting "expression must be integral or enum data type" on the fstreams in this code . I'm guessing its something with the way I'm handling wiritng to the binary file (I'm having to use an OLD unix compiler for this class so bear in mind its old non standard stuff)
Code:
#include <fstream.h>
#include <ctype.h>
struct employee
{
char id[3],
fname[10],
lname[10],
salary[10];
};
int main (void)
{
fstream fin,
foutbad,
foutgood;
fin.open("hwk07.txt", ios::in);
foutgood.open("hwk07.bin", ios::out);
foutbad.open("errorlog.txt", ios::out);
void readfile (fstream&, fstream&, fstream&);
readfile (fstream& fin, fstream& foutgood, fstream& foutbad);
return 0;
} // main
// *** readfile ***
void readfile (fstream& fin, fstream& foutgood, fstream& foutbad)
{
employee goodemployee[100],
bademployee[100],
temp;
int goodcounter = 0,
badcounter = 0,
i;
bool checkresult,
checkdata (employee&);
void writefiles (fstream&, employee&);
while (fin >> temp.id)
{
fin >> temp.fname >> temp.lname >> temp.salary;
checkresult = checkdata(employee& temp);
if (checkresult)
{
goodemployee[goodcounter] = temp;
goodcounter++;
} // if
else
{
bademployee[badcounter] = temp;
badcounter++;
} // else
} // while
if (badcounter != 0)
{
cout << "File contained " << badcounter << "erroneous record(s).";
} // if
for (i = 0; i <= goodcounter && goodcounter > 0; i++)
{
if (goodemployee[i].id > goodemployee[i+1].id)
{
temp = goodemployee[i+1];
goodemployee[i+1] = goodemployee[i];
goodemployee[i] = temp;
} // if
} // for
writefiles (fstream& foutgood, employee& goodemployee);
writefiles (fstream& foutbad, employee& bademployee);
} // readfile
// *** checkdata ***
bool checkdata (employee& temp)
{
bool result = true;
int i;
for (i = 0; i < 4 && result == true; i++)
{
if (isalpha(temp.id[i]) == true )
result = false;
if (ispunct(temp.id[i]) == true )
result = false;
} // for
for (i = 0; i < 10 && result == true; i++)
{
if (isalpha(temp.salary[i]) == true )
result = false;
} // for
return result;
} // checkdata
// *** writefiles ***
void writefiles (fstream& fout, employee& data)
{
fout << "Programmed by:\nAaron Friedley\nChris Reynolds\nLena King\n\n"
<< "\tSalary Data\n ID Name Salary";
fout << data.id << " " << data.fname << ", " << data.lname << " "
<< data.salary;
}