Sorting structs

In order to become familiar with structs, I'm trying to write a program that will input an unordered set of names of students in a class and their grade in that class and then sort them both alphabetically and by grade. I'm only to the first sorting part of the program and it's compiling fine but my code keeps crashing with this error:

"SortingStructs.exe!main() Line 41
SortingStructs.exe!_tmainCRTStartup() Line 536
SortingStructs.exe!mainCRTStartup() Line 377"

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
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
#include <string>

using namespace std;

typedef char Name[40];
struct Rec{Name fname; double fgrade;};
Rec Class[100];
Rec Class_Alpha[100];
Rec Class_Grade[100];

void open()
{
ifstream infile("list.txt", ios::in);
	if (!infile.good()){
		cout<< "cant open file"<<endl;
		exit(1);}

int i=0;
for(i=0; !infile.eof();i++){
	infile >> Class[i].fname>>Class[i].fgrade;
	}
}

void main()
{
open();
// sort by grade 
int i=0;
int j=0;
for(i=0; i<5;i++)
	{Rec temp = Class[i];
		for(j=i+1;j<5;j++){
			if (Class[j].fgrade < temp.fgrade)
			{temp = Class[j];}
		}
		Class_Grade[i]=temp;
		cout << Class_Grade[i].fgrade << endl;
	}
_getch();
}


The compiler then indicates that the problem arose at the line {temp = Class[j];}

I don't see anything wrong with this, any input?

Thanks in advance!
Topic archived. No new replies allowed.