Hi! I am trying to build a code to read the data from a text file into the array and display all records but it is not working and I am not sure how to fix the issues or how to even correctly use the file name as a parameter. Any tips would be greatly appreciated!
#include <iostream>
#include <fstream>
usingnamespace std;
constint N=5;
struct RECORD
{
char Name[15];
int Age;
float Gpa;
};
RECORD p[N];
void CopyRecords (char Name, int x[], int n);
void Display (RECORD x[], int 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 (char Name, int x[], int n)
{
fstream f;
f.open ("data2.txt");
for (int i = 0; i < n; ++i)
{
f >> x[];
}
}
void Display (RECORD x[], int n)
{
for (int i = 0; i < n; ++i)
{
cout << x[i].Name << " " << x[i].Age << " " << x[i].Gpa << '\n';
}
}