Hi, I'm having a little bit of trouble copying data from a text file and displaying it in an array. Not sure how to proceed further and any help would be appreciated.
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
constint N=5;
struct RECORD
{
char *Name;
int Age;
float Gpa;
};
RECORD p[N];
void CopyRecords (string filename, RECORD p[N]);
void Display (RECORD x[N]);
int main()
{
//Read data from this file into array p
CopyRecords("data2.txt", p);
//Display all records
Display(p);
//Terminate Program
system ("pause");
return 0;
}
void CopyRecords (string filename, RECORD p[N])
{
ifstream f;
f.open(filename, ios::in);
for(int i = 0; i <= N; ++i)
{
f >> p[i].Name >> p[i].Age >> p[i].Gpa;
}
}
void Display (RECORD x[N])
{
for (int i = 0; i < N; ++i)
cout << x[i].Name << " " << x[i].Age << " " << x[i].Gpa << endl;
}
This is what I've changed so far. The code won't compile. I think what my issue is I've tried to populate the RECORD struct from the data2.txt, but I believe my issues lie within the CopyRecords function. I don't think its populating correctly.