Bonjour,
mon pgm se plante, message : fichier.exe a cessé de fonctionner.
Je pense c'est lié à la fonction scanf() utilisée plusieurs fois dans une même boucle. Quand j'utilise une seule fois scanf() ça marche. J'ai prévu de vider le buffer mais ça n'a rien donné.
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
29
30
31
32
33
34
35
36
37
38
39 #include<stdio.h> #include<string.h> void vider_stdin(void) { scanf("%*[^\n]"); getchar(); } int main() { int const n=4; struct produit { char libelle[50]; float prix; float tva; }; struct produit tabProduit[n]; int i; char nom_type_produit[30]; for (i=0; i<=n-1; i++) { printf("Libellé : "); scanf("%s", tabProduit[i].libelle); vider_stdin(); printf("Prix : "); scanf("%f", &tabProduit[i].prix); vider_stdin(); printf("TVA : "); scanf("%f", tabProduit[i].tva); vider_stdin(); } return 0; }
Quelqu'un peut m'aider.
Merci par avance.
Partager