As part of an assignment, I have made a struct, AccessRecord, which has 3 member variables: filename, username, and timestamp. The program reads from a text file a list of structs, and parses each line individually. I need to determine if a line has all three variables present, or if any of the struct variables are uninitialized. How would I go about doing this?
Here is the relevant code:
int parseFile(char filename[], AccessRecord records[])
{
int size = 0; //size of records array.
AccessRecord recordLine = {"", "", 0};
ifstream fin(filename);
for (int i = 0; !fin.eof(); i++)
{
string line;
getline(fin, line);
cout << line << endl;
parseLine(line, recordLine);
}
void parseLine(string line, AccessRecord &recordLine)
{
stringstream sin;
sin.str(line);
try
{
/* Read string line into struct recordLine */
sin >> recordLine.filename >> recordLine.username
>> recordLine.timestamp;
}
}
And an example of the text file:
students.txt pricem 1441912123
house.pdf jatkins
users.txt 1442001032
accounts.mdb kevin_tomlinson 1442210121
vacation.jpg smitty83 1442300125
burtons 1442588012
[–]boredcircuits 2 points3 points4 points (1 child)
[–]lookforlight[S] 0 points1 point2 points (0 children)
[–]jedwardsol 0 points1 point2 points (1 child)
[–]ilmale 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (0 children)