2 Replies - 769 Views - Last Post: 08 April 2013 - 04:29 AM Rate Topic: -----

#1 kingomalek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-April 13

From Text file to dynamic array of struct ?

Posted 08 April 2013 - 02:37 AM

the file exemple

9999999 eeee iiiiii kkkkk 13 \n
8888888 aaaa bbbbb dddd 15 \n


void trie(FILE *fp, char s[]) //s is the name or the adresse of the file and fp is the pointer
{int size,i=0;
typedef struct etudiant
{
    int cin;
    char name[50];
    char lastname[50];
    char classe[50];
    float note;
}etudiant;
fp=fopen(s,"r");
fseek(fp, 0, SEEK_END);
size = ftell(fp);// the size pf file
fseek(fp, 0, SEEK_SET);
etudiant *tab= malloc(sizeof(etudiant) * size); // i try to create a dynamic array of struct



printf("%d",size);
// in my programe i used while not EOF i repeat this
    fscanf(fp,"%d %s %s %s %f \n",&tab[i].cin,tab[i].name,tab[i].lastname,tab[i].classe,&tab[i].note);
    i++;
    printf("done");



printf(fp,"%d %s %s %s %f \n",tab[0].cin,tab[0].name,tab[0].lastname,tab[0].classe,tab[0].note);
    fclose(fp);

}

the program return unknown characters "?F!" like that
i just want to know where is the problem

Is This A Good Question/Topic? 0
  • +

Replies To: From Text file to dynamic array of struct ?

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: From Text file to dynamic array of struct ?

Posted 08 April 2013 - 02:48 AM

printf(fp,"%d %s %s %s %f \n",tab[0].cin,tab[0].name,tab[0].lastname,tab[0].classe,tab[0].note);


Why is the first argument to printf here a FILE*?

Turn up your warning level and fix any warnings that show up.
Was This Post Helpful? 1
  • +
  • -

#3 kingomalek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-April 13

Re: From Text file to dynamic array of struct ?

Posted 08 April 2013 - 04:29 AM

thanks it 's a stupid mistake :nottalkingtoyou:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1