Code:
#include<stdio.h>
#include<stdlib.h>
struct data_struct
{
int id;
char fname[25];
char lname[25];
int height;
int age;
char degree[30];
int bday;
float wage;
};
int main()
{
struct data_struct record[1000];
FILE *fp;
fp = fopen("input", "r");
if(fp == NULL)
{
printf("error opening input");
exit(1);
}
int N = 0;
fscanf(fp, "%d, %c, %c, %d, %d, %c, %d, %f", record[N].id, record[N].fname[25], record[N].lname[25], record[N].height, record[N].age, record[N].degree, record[N].bday, record[N].wage);
while( !feof(fp) )
{
for(N = 0; N<200; N++)
{
printf("ID: %d \n%c %c \nHeight: %d \nAge: %d \nDegree: %c \nBirthDate: %d Wage: %f", record[N].id, record[N].fname[25], record[N].lname[25], record[N].height, record[N].age, record[N].degree, record[N].bday, record[N].wage);
}
}
return 0;
}
The goal of this is to read from a file that looks like this with much more input in it...
THIS IS AN EXAMPLE:
Code:
100
John
Doe
73
19
Cs
11051991
7.71
101
George
Washington
75
18
cons
05141992
5.01
In order from top to bottom it goes: ID Number, First Name, Last Name, Height (inches), Age, Degree, birthdate(dd/mm/yyyy), wage.
When I run the file I get a seg fault and can't figure out what my problem is...