probleme taille de tableau
bonjour à tous,
j'ai un probleme lors de l'affichage d'un tableau statique
Code:
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},
}; |
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:
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);
} |
il m'affiche:
Citation:
EVENTAB: CAPAB
EVENTAB: SERVER
EVENTAB: PING
EVENTAB: BURST
EVENTAB: ENDBURST
EVENTAB: ERROR
EVENTAB: (null)
EVENTAB: (null)
EVENTAB: *û
EVENTAB: (null)
EVENTAB: (null)
EVENTAB: (null)
d'ou vient le probleme ?
merci d'avance