Bonjour à tous,
Je veux qu'une fonction génère un tableau de structure de taille variable.
Le code ci-desous fonctionne :
Je créer le tableau de structure dans une fonction externe, avec le programme suivant qui ne fonctionne 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 typedef struct { unsigned char cLib [15]; unsigned char cNum; } stParamStruct; void ExeScan ( void ) { char dbgMax =5; char i; char buf [100]; stParamStruct *stParTab; stParTab = malloc(dbgMax); // créé et rempli tableau structure for ( i = 0; i<dbgMax ;i++) { sprintf(buf,"Num %d", i); strcpy( (char *)((stParTab+i)->cLib), buf); } DialScan (stParTab, dbgMax ); // passe le tableau de structure en //argument free(stParTab); }
Ou est l'erreur ? Comment faut-il faire pour faire fonctionner la fonction GenereTab ?
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 void GenereTab( stParamStruct **tParTab, char nombre) { // nouvelle fonction char i, buf[50]; stParamStruct *local; local = malloc(nombre); // créé et rempli tableau structure for ( i = 0; i<nombre ;i++) { sprintf(buf,"Num %d", i); strcpy( (char *)((local+i)->cLib), buf); } *tParTab = local; // plantage !!!!! } void ExeScan ( void ) { stParamStruct *stParTab, **bis; GenereTab( bis, 5); stParTab = *bis; DialScan (stParTab, 5);// passe le tableau de structure en argument free(stParTab); }
Merci d'avance.
Partager