Hello everyone,
I get a "Segmentation Fault" when I try to run this program. I think my problem is with the structs and enum. Specifially the enum but I could be wrong. I have enclosed my classes.h file and loadFile.c file.
Code:
#ifndef CLASSES_H_INCLUDED
#define CLASSES_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
typedef enum {MW, TR} days;
typedef struct {
int hour, min;
} Time;
typedef struct {
char Dept[5];
int course, sect;
days meet_days;
Time start, end;
char instr[20];
} sched_record;
#endif // CLASSES_H_INCLUDED
Code:
#include "classes.h"
void main()
{
FILE *filePointer;
sched_record data;
filePointer = fopen ("classes.db", "rb");
if (filePointer == NULL)
{
puts("Cant open file");
exit(1);
}
while (!feof(filePointer))
{
if(fread(&data, sizeof(sched_record), 1, filePointer)!=0)
{
printf("\n%s %d %d %s %d %d %s", data.Dept, data.course, data.sect, data.meet_days, data.start, data.end, data.instr);
fclose(filePointer);
}
}
}
The file we are to use is a binary file and it is called classes.db. Now we have a text representation and it is as follows:
Code:
Math 102 10 M 0800 0850 Schulte
Eng 033 1 T 0930 1050 Shakespeare
Art 308 2 M 0800 1150 VanGogh
Anth 055 13 T 1200 1325 Kroeber
CS 125 2 T 0800 0850 Hoare
Eng 202 10 M 1000 1050 Chaucer
Chem 100 5 T 1100 1250 Pauling
Phys 395 2 T 1200 1250 Einstein
CS 125 4 M 1030 1120 Knuth
Math 420 2 T 0800 0950 al-Khowarizmi
Does anyone know how I might correct this? I appreciate any help.