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 40 41
| typedef struct
{
char *intitule;
char *value;
} Parametre;
typedef struct
{
char *intitule;
Parametre *parametres;
} Commande;
Commande * parse_commande ( char * buffer )
{
...
Commande *com;
...
com = (Commande *) malloc ( sizeof ( Commande ) ); // Allocation de la mémoire pour la commande
com->parametres = (Parametre *) malloc ( 0 ); // Allocation de la mémoire du tableau de param
...
com->intitule = (char *) malloc ( sizeof (char) * size_intitule );
strncpy ( com->intitule, pt_com1, size_intitule );
...
for ( ... )
{
...
com->parametres = (Parametre *) realloc ( com->parametres, i * sizeof ( Parametre ) );
...
intitule = (char *) malloc ( sizeof ( char ) * size_intitule_param );
com->parametres[i].intitule = intitule;
strncpy ( com->parametres[i].intitule, pt_com1, size_intitule_param );
...
value = (char *) malloc ( sizeof ( char ) * size_value_param );
...
strncpy ( com->parametres[i].value, pt_com1 + size_intitule_param, size_value_param );
}
return com;
} |
Partager