Wednesday 15 July 2015

c - How to use #define in struct initialisation -



c - How to use #define in struct initialisation -

i don't know if title clear enough, here want do. want utilize #define define size of array in struct.

i'm doing this, don't want work :

#ifndef def_main #define def_main #define taille_tab = 100; typedef struct personne personne; struct personne { char nom[taille_tab]; char prenom[taille_tab]; int age; }; #endif

but error.

if instead put:

{ char nom[100]; char prenom[100]; int age; };

then works... why first solution doesn't work ? =( can't utilize #define var on code on same file ?

your syntax wrong, it's:

#define taille_tab 100

c

No comments:

Post a Comment