Bonjour à tous,
Voila j'ai un problème pour charger des informations d'un fichier texte avec scanf.
Je stocke dans un fichier des informations de ce type :
J'ai créé une fonction pour récupérer ces valeurs mais j'ai un gros problème dès qu'il faut charger des floats.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 4 Ballon 10.0 decembre 15.00 Stylo 3.0 21/12/06 5.00 Maillot 46.0 21/12/06 50.00 Voiture 1000.0 25/12/06 1200.00
Voici ma fonction :
Est ce que quelqu'un pourrait m'expliquer pourquoi ce code ne marche pas???
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 unsigned int nbObjets; struct objet * Objets; void charger_objets(char fichier_objets[50]) { FILE * fich_obj; unsigned int i; if ((fich_obj=fopen(fichier_objets,"rb"))==NULL) { fprintf(stderr,"Erreur a l'ouverture du fichier contenant les objets %s\n",fichier_objets); exit(0); } fscanf(fich_obj,"%d\n",&nbObjets); Objets=alloc_objets(Objets, nbObjets); for (i=0; i<nbObjets; i++) { fscanf(fich_obj, "%s %.2f %s %.2f\n", &Objets[i].nom_objet, &Objets[i].mise_a_prix, &Objets[i].date_fin, &Objets[i].seuil); } for (i=0; i<nbObjets; i++) { printf("Objet : %s, Prix : %f, Date fin encheres : %s, Seuil : %f\n",&Objets[i].nom_objet,&Objets[i].mise_a_prix, &Objets[i].date_fin, &Objets[i].seuil); } }
Car pour l'instant cette fonction m'affiche ceci :
Merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Objet : Ballon, Prix : 0.00, Date fin encheres : , Seuil : 0.00 Objet : Stylo, Prix : 0.00, Date fin encheres : , Seuil : 0.00 Objet : Maillot, Prix : 0.00, Date fin encheres : , Seuil : 0.00 Objet : Voiture, Prix : 0.00, Date fin encheres : , Seuil : 0.00
Partager