Hi. I'm trying to write this program where i read data from a file to
an array of structure. here are parts of it.
----------------------------------------------------------
struct employee
{
char name[20];
int empnumber;
};
employee file[20];
void file2(employee *c);
main()
{
employee *fileptr;
fileptr=file;
file2(fileptr); // the function file2 is located on a different file
named file2.cpp.
}
---------------------------------------------------------------
file2(employee *c)
{
ifstream input;
input.open("data.txt",ios::in);
if (!input)
cout << "error";
else
while (!input.eof())
{
for (int i=0; i<=20; i++)
{
input.getline(c->name,20);
input >>(c->empnumber);
}
}
input.close();
}
I'm a beginner. anyone know what's wrong with this?
i get the error in file2 that "error C2227: left of '->name' must
point to class/struct/union."
the c->name and c->empnumber above has an index of i. for some reason, it didn't show up in the post.