SarahKate31
Programmer
Hello all...I am a beginner when it comes to C++ so hopefully someone can help! I am writing a program that should read from a .dat file into an array of structs...The first part of each line of the file will read into one variable and the second part will read into another, but I can't figure out how to find out when I've reached the end of the file since I don't know how big it is. The code I have so far seems to work except for the line determining EOF ---
int ReadData (STAR Array [])
{
static int i = 0;
static int number = 1;
static ifstream starFile ("star.dat"
if (starFile.fail())
{
cerr << "An error occured in opening the file." << endl;
exit (1);
}
if (starFile.eof)
{
return i;
}
else
{
Array.Num = number;
starFile.getline (Array.itemName, 22, ',');
starFile.getline (Array.price, 7, '\n');
i ++;
number ++;
ReadData (Array);
return i;
}
}
Any insight would be much appriciated!!
int ReadData (STAR Array [])
{
static int i = 0;
static int number = 1;
static ifstream starFile ("star.dat"
if (starFile.fail())
{
cerr << "An error occured in opening the file." << endl;
exit (1);
}
if (starFile.eof)
{
return i;
}
else
{
Array.Num = number;
starFile.getline (Array.itemName, 22, ',');
starFile.getline (Array.price, 7, '\n');
i ++;
number ++;
ReadData (Array);
return i;
}
}
Any insight would be much appriciated!!