Read data from file !!!

This is a discussion on Read data from file !!! within the C Programming forums, part of the General Programming Boards category; Hello,nice to meet you all... i want to read some data from the text file and then insert each row ...

  1. #1
    frankiepoon
    Guest

    Unhappy Read data from file !!!

    Hello,nice to meet you all...

    i want to read some data from the text file and then insert each row data into the link list....

    now i have some problems want to ask....
    Firstly, the data file structure is like this :

    111 111 -1
    12222 123131
    121212
    131313133131313 234234234234234324
    13131334
    1313133131313
    1212
    1212
    11
    324234234234

    You can see that the structure of the data file is not fixed...
    i don't know how to read the data from the file and then put into the array.....

    if i can put the data into array....i think i can solve the problems!!

    THX!!

  2. #2
    Registered User Seek n Destroy's Avatar
    Join Date
    Sep 2002
    Posts
    9
    if the structure is not fixed, you can save it like strings and read it like this

    void read(void)
    {
    typedef struct data{
    char dataa[100];
    char datab[100];
    }type;
    type data;
    char c;
    int howlong;
    FILE *read
    if((read=fopen("textfile.xxx","rt"))==NULL)
    exit(1);
    while(c!="\0")
    c=fgetc(read);
    howlong=ftell(read);
    rewind(read);
    fread(data->dataa,howlong,1,read);
    fseek(howlong,read,SEEK_SET);
    /* then the same code for next data*/
    fclose(read);
    }

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    fgets(), fscanf() might be your solution

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  2. Read data from file - C program ?
    By Pawan Sangal in forum C Programming
    Replies: 2
    Last Post: 08-22-2008, 05:28 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21