So, I have this function that I wrote about a month ago and forgot exactly how it works.
int readFile(int racerId_func[30], double raceData_func[30][8]) {
string fileLoc;
ifstream inFile;
int racersNum_func;
cout << "Enter an input filepath: "; // Type in the filepath
getline(cin, fileLoc);
inFile.open(fileLoc);
if (inFile.fail()) {
cout << "Error: Could not open file." << endl;
exit(1);
}
inFile >> racersNum_func; // Gets the number of racers
for (int i=0; i < racersNum_func; i++) {
inFile >> racerId_func[i]; // Assigns each racer's ID number
for (int j=0; j < 8; j++) {
inFile >> raceData_func[i][j];
}
}
return racersNum_func;
}
This is supposed to read from a file the number of racers, then the ID and lap times of each racer. Notice that it only returns racersNum. Now, I call upon this function my main function like so:
int racersNum, racersQual; // vars included for reference
int racersDis = 0;
int racerId[30];
double raceData[30][8];
double average[30];
racersNum = readFile(racerId, raceData); // I call it right here
Somehow, racerId and raceData are also passed back from the function, even though I only returned racersNum. Why is this? Do I have a fundamental misunderstanding of how return works? Do you need to see my whole program?