So, I'm doing a college assignment where basically what is needed is that you use a pointer that points to a dynamically allocated array of the correct size based on input from a data file. The problem is, I keep getting different errors when the program runs. The program compiles perfectly fine, but yet when it runs, it gives me this: "0xC0000005: Access violation reading location 0xFDFDFDFD."
Here is the code I'm using (do note that some of the code was written by my professor and before you ask, I attempted to contact him, and never got anything back from him):
Written by Professor
struct emprec /*Employee record with two fields*/
{
int id;
float salary;
};
typedef emprec* emprecptr; /*Employee record pointer type*/
typedef emprecptr* indexarr; /* Pointer to a dynamic array of employee record pointers*/
Written by me
void readdata(indexarr& ptrs, int& size)
{
size = 0;
ptrs = nullptr;
ptrs = new emprecptr[size];
ifstream in;
in.open("p1data.txt");
if (!in) {
cout << "Unable to open p1data.txt"; //if the file is not in the folder
exit(1);
}
while (!in.eof()) {
in >> ptrs[size]->id; //putting to read line for id
in.ignore();
in >> ptrs[size]->salary; //putting to read line for salary
in.ignore();
size = size + 1;
}
in.close();
};