I know that if I don't use up all the space in an array that the computer will just fill it with garbage values, but how do I stop them from showing up in the output? The user cannot specify the size of the array either (professor made it that way for this lab). I am reading from a text file if that helps.
const int STUDENTS = 50; //size of array
struct StudentInfo
{
string name;
char char_name[SIZE];
int idnumber;
int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;
};
int main()
{
StudentInfo student[STUDENTS];
ifstream inFile;
int i = 0;
inFile.open("guesses.txt");
if (!inFile)
cout << "\n\n**** ERROR OPENING FILE. ******\n" << endl;
else
{
while (!inFile.eof())
{
inFile >> student[i].idnumber;
inFile.getline(student[i].char_name, SIZE, '\n');
student[i].name = student[i].char_name;
inFile >> student[i].num1;
inFile >> student[i].num2;
inFile >> student[i].num3;
inFile >> student[i].num4;
inFile >> student[i].num5;
inFile >> student[i].num6;
inFile >> student[i].num7;
i++;
if (inFile.eof())
break;
}
for (int i = 0; i < STUDENTS; i++) //loop i use for output
{
cout << left;
cout << setw(5) << student[i].idnumber;
cout << setw(15) << student[i].name;
cout << right;
cout << setw(6) << student[i].num1;
cout << setw(6) << student[i].num2;
cout << setw(6) << student[i].num3;
cout << setw(6) << student[i].num4;
cout << setw(6) << student[i].num5;
cout << setw(6) << student[i].num6;
cout << setw(6) << student[i].num7;
cout << endl;
}
cout << endl << endl << endl;
inFile.close();
system("pause");
}