ok, d'accord je comprends, je vais corriger ça merci beaucoup
je reviens car je me demande si je dois initialiser mon tableau de structure avant de l'utiliser ?
Je mets mon code (simplifié) ci-dessous. Je n'ai pas de message particulier à la compilation mais ça plante à l'exécution (Segmentation fault). Si je mets 0 à la place de j dans le do while, ça fonctionne.
Dois-je faire une initialisation du genre :
sizeof(taxon_info)*RESULT_LENGTH
avec malloc ?
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 42 43 44 45 46
| typedef struct {
char *sci_name;
int32_t tax_id;
int32_t tax_rank;
} taxon_info ;
#define PATTERN_NUMBER 10
#define PATTERN_LENGHT 40
#define RESULT_LENGTH 100
int main(int argc, char **argv)
{
int32_t carg;
int32_t numpattern=0;
int32_t k,j=0;
char *taxon;
char pattern[PATTERN_NUMBER][PATTERN_LENGHT];
taxon_info taxonlist[RESULT_LENGTH];
ecotaxonomy_t *taxonomy;
int re_error;
int re_match;
regex_t re_preg;
while ((carg = getopt(argc, argv, "t:")) != -1) {
switch (carg) {
case 't':
strncpy(pattern[numpattern],optarg,PATTERN_LENGHT);
numpattern++;
break;
}
}
taxonomy = read_taxonomy(prefix);
do {
taxon = taxonomy->taxons->taxon[j].name;
taxonlist[j].sci_name = taxon;
taxonlist[j].tax_id = taxonomy->taxons->taxon[j].taxid;
taxonlist[j].tax_rank = taxonomy->taxons->taxon[j].rank;
j++;
} while(taxon != NULL);
return 0;
} |
merci d'avance pour vos conseils
Partager