I'm having trouble displaying my text file correctly. Theres a debug error message that says stack around variable student is corrupted
here is all the code I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
const int NUM_SCORES = 6;
typedef struct
{
int day;
int month;
int year;
} Date;
struct Student
{
int number;
Date dob;
float scores[NUM_SCORES];
} ;
const int MAX_ITEMS = 10;
struct ListType
{
int length;
int info[MAX_ITEMS];
}; ListType list;
int _tmain(int argc, _TCHAR* argv[])
{
Student student [15];
ListType list;
list.length = 0;
ifstream infile ("StudentFile.txt");
while(!infile.eof())
for (int i = 0; i < 15; i++)
{
infile >> student[i].number >> student[i].dob.day >> student[i].dob.month >> student[i].dob.year >> student[i].scores[6];
}
cout << "The Class List Is: " << endl;;
for (int i = 0; i < 15; i++)
{
cout << student[i].number << "\t" << student[i].dob.day << "/" << student[i].dob.month << "/" << student[i].dob.year << "\t" << student[i].scores[6] << endl;
}
infile.close();
return 0;
}
| |
the code should look the this:
040023 23 4 1986 1 1 1 1 1 1
040028 16 9 1985 2 2 2 2 2 2
040029 1 5 1986 3 3 3 3 3 3
040032 12 3 1984 4 4 4 4 4 4
040034 31 8 1986 5 5 5 5 5 5
040035 20 9 1985 6 6 6 6 6 6
040038 17 5 1983 7 7 7 7 7 7
040045 9 2 1980 8 8 8 8 8 8
040047 6 6 1986 9 9 9 9 9 9
040049 10 3 1985 10 10 10 10 10 10
040051 29 5 1983 11 11 11 11 11 11
040054 15 7 1986 12 12 12 12 12 12
040057 26 11 1982 13 13 13 13 13 13
040068 27 10 1981 14 14 14 14 14 14
040070 18 3 1986 15 15 15 15 15 15
But the output looks like this:
The Class List Is:
8 8/8/8 5.61178e-041
40047 6/6/1986 1.26117e-044
9 9/9/9 5.61206e-041
40049 10/3/1985 1.4013e-044
10 10/10/10 5.61234e-041
40051 29/5/1983 1.54143e-044
11 11/11/11 5.61276e-041
40054 15/7/1986 1.68156e-044
12 12/12/12 5.61318e-041
40057 26/11/1982 1.82169e-044
13 13/13/13 5.61472e-041
40068 27/10/1981 1.96182e-044
14 14/14/14 5.615e-041
40070 18/3/1986 2.10195e-044
15 15/15/15 15 |
I don't know why the student variable is corrupted