Hi i am quite new to C.Wanted help on a segmenation fault in the foll program >>
Am simply trying to read file contents into variables defined in struct data
Code:
Code:
#include<stdio.h> 
int main() 
{ 
const MAX = 1000; 
struct data { float *lat[MAX]; 
float *lon[MAX]; 
float *hc100[MAX]; 
int day[MAX]; 
int month[MAX]; 
int year[MAX]; 
int jd[MAX]; 
int n[MAX]; 
char *d[MAX]; 
}; 
int i; 
struct data data1; 
FILE* fp; 
fp = fopen("hc100-Ebox.par","rw"); 
if(fp == NULL) 
{ 
printf("FILE DOESNT EXIST"); 
goto l1; 
} 
while(!feof(fp)||i<MAX) 
{ 
fscanf(fp,"%f %f %d %d %d %f %d %c  %d",data1.lat[i],data1.lon[i],&data1.day[i],&data1.month[i],&data1.year[i],data1.hc100[i],&data1.jd[i],data1.d[i],&data1.n[i]); i++; } 
fclose(fp); 
l1:return 0; 
}
A fragment of the data i am trying to read is :
9.65 75.58 9 5 2002 282.68 129 E 1
10.08 75.43 24 5 2002 261.08 144 E 2
10.08 75.45 13 6 2002 233.84 164 E 3
10.20 75.70 14 6 2002 262.54 165 E 3
10.12 75.25 3 7 2002 236.79 184 E 4
10.05 75.65 7 7 2002 99.99 188 E 4
10.00 75.83 22 7 2002 99.99 203 E 5
and it continues for some lines below the same way,,,

Last edited by shabbir; 3Apr2008 at 18:32.. Reason: Code block