I am trying to read files then display them on the Display function. Can anyone please tell me what is wrong with this code? I am super confused right now. I have structs as well.
1 2 3 4 5 6
struct Record
{
string username;
string fileName;
long timeStamp;
};
The problem with the code is that, for some reason, it is not looping through the file then not displaying the file that was read. Please help me!
Not quite. Recall that the function parameter is a pointer already, so reference-ness isn't required (the pointer does the job.)
The type of function parameters that are arrays of any type T or some function type F are replaced with the corresponding pointer type T* or pointer-to-function type F*.
That is, the declaration
int readFile(constchar fileName[], Record records[])
Is generally the same as
int readFile(constchar* fileName, Record* records)
It is not possible to create an array-of-references, so the declaration &Record records[] is a syntax error. It is possible to create a reference-to-array, which looks like T(&records)[N].
Thanks for telling me about the while loop problem. It feels super small but it makes so much difference. However, the display Function is still not working. I just don't get what is wrong with it.
Lines 30-31: It's not entirely clear where times[0] and times[1] come from.
If you're asking the user to enter two times and you looking for the records that are between those two times, then your if statement is wrong. As written, you're checking if the timestamp of a record is >= the first time and also >= second time. If your records are in ascending time order, this condition will be true for all records that are greater than the second time.