I find it difficult to understand how to pass a file to a function.
I have a file with 20 names and 20 test results that need to be read by a function. the function will then assign names and ratings to the structure called the student.
My question is how to write a function call with the appropriate parameters.? so that my function reads the data in the file. thank.
CODE
cout << "Enter the name of the file for the student data to be read for input" << endl;
cout << " (Note: The file and path cannot contain spaces)" << endl;
cout << endl;
cin >> inFileName;
inFile.open(inFileName);
cout << endl;
ReadStudentData(inFile, student, numStudents );
void ReadStudentData(ifstream& infile, StudentType student[], int& numStudents)
{
int index = 0;
string lastName, firstName;
int testScore;
while ((index < numStudents) &&
(infile >> lastName >> firstName >> testScore))
{
if (testScore >= 0 && testScore <= 100)
{
student[index].studentName = lastName + ", " + firstName;
student[index].testScore = testScore;
index++;
}
}
numStudents = index;
}
source
share