[C] How to load data from text file like this

data.txt
ANDY | 2 | male |
MARY | 5 | female |
BOB | 9 | male
MARIA | 8 | female |
MICHEAL | 5 | homo |


1
2
3
4
5
  struct _student
   {
    int age;
      char name[10], sex[10];
   } std[10];

How can I load data from data.txt and store each line for each record of std[] (In C language).

I think we can use fscanf to get data from eachline instead of geting all line as a string and then work with string.
Like that:
fscanf(fpt,"%20[^|]|%d|%20[^|]",st[0].name,&st[0].age,st[0].sex);

But I can get just the first line and dont know how to get the others. How can I set the poiter to the next line after use fscanf?

Please help me! I'm newbie
Last edited on
Topic archived. No new replies allowed.