#include<iostream> #include<fstream> using namespace std; struct Students { char
ID: 3652164 • Letter: #
Question
#include<iostream>#include<fstream>
using namespace std;
struct Students
{
char name[40];
int id_num;
double gpa;
};
int getInfo(Students student_info[ ]) //function header
{
int number_stu ;
ifstream inFile; //Input file stream to open file and read
int i = 0; //index for position in array of structures
inFile.open("student.txt"); //open file to read from
if(!inFile) //check to see if file is open
cout << " **** ERROR OPENING FILE. ****** " << endl;
else
{
while (!inFile.eof()) //while not at the end of file(eof)
{
inFile >> student_info[i].id_num; //read student id
inFile.getline(student_info[i].name, 50, ' ');//get name
//store in string member of structure
inFile >> student_info[i].gpa; //read GPA
i++;
if (inFile.eof()) //if end
Explanation / Answer
there bis some problem in your code...you should know the number of students present in the file before you enter into the function getinfo. and your getinfo function should be void type assuming that there is the info of 10 students in the file int main() { Students stu[10]; getinfo(stu); } please rate me I would correct the code for you and give it in comments if you want me to do so...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.