bonjour à tous,
j'ai un probleme lors de l'affichage d'un tableau statique
lorsque j'affiche la taille du tableau via un sizeof(evntab), il me retourne bien 6 elements par contre lorsque je le parcours de cette maniere
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 static struct servEvents { const char *cmd; //int (*fct) (int, char **); int t; } evntab[] = { {"CAPAB", 15}, {"SERVER", 18}, {"PING", 21}, {"BURST", 25}, {"ENDBURST", 27}, {"ERROR", 30}, };
il m'affiche:
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 /* array size */ #define ASIZE(x) (sizeof (x) / sizeof *(x)) static void irc_parse(char *buf) { char *tab[MAXPARAMS]; char *cmd = NULL; int count = 0, indice = 0; size_t i = 0; while (*buf) { while (*buf == ' ') *buf++ = 0; if (*buf == ':') { buf++; indice = 1; } if (count == indice && !cmd) cmd = buf; else tab[count++] = buf; while ((*buf) && (*buf != ' ')) buf++; } tab[count] = NULL; for (;ASIZE(evntab);i++) printf("EVENTAB: %s\n", evntab[i].cmd); }
d'ou vient le probleme ?EVENTAB: CAPAB
EVENTAB: SERVER
EVENTAB: PING
EVENTAB: BURST
EVENTAB: ENDBURST
EVENTAB: ERROR
EVENTAB: (null)
EVENTAB: (null)
EVENTAB: *û
EVENTAB: (null)
EVENTAB: (null)
EVENTAB: (null)
merci d'avance
Partager