Sementation fault dealing with files

Discussion in 'C' started by josh53221, Apr 3, 2008.

Thread Status:
Not open for further replies.
  1. josh53221

    josh53221 New Member

    Joined:
    Apr 3, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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:
    #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,,,

    Kindly help me out !
     
    Last edited by a moderator: Apr 3, 2008
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice