Un peux de pointeur en C :D
Résolu
Bonjour,
Voila mon petit problème
J'ai un structure qui contient un tableau,
typedef struct {
unsigned char tableau[10];
}_structtableau
j'ai un pointeur sur cette structure
_structtableau struct1;
_structtableau pnt_struct1 = &struct1 ;
Je souhaite maintenant faire pointé un pointeur sur la 1er case du tableau mais le code suivant :
unsigned char *pnt_tbl;
pnt_tbl = pnt_pnt_struct1->tableau;
ne me donne pas la bonne réponse...
Des idée parce que je bloque bien... ?
Merci
Voila mon petit problème
J'ai un structure qui contient un tableau,
typedef struct {
unsigned char tableau[10];
}_structtableau
j'ai un pointeur sur cette structure
_structtableau struct1;
_structtableau pnt_struct1 = &struct1 ;
Je souhaite maintenant faire pointé un pointeur sur la 1er case du tableau mais le code suivant :
unsigned char *pnt_tbl;
pnt_tbl = pnt_pnt_struct1->tableau;
ne me donne pas la bonne réponse...
Des idée parce que je bloque bien... ?
Merci
Configuration: Windows 7 / Firefox 3.6
3 réponses
-
Contributeurhello
typedef struct { unsigned char tableau[10]; }_structtableau ; /* il manque un ; */ _structtableau struct1; _structtableau *pnt_struct1 = &struct1 ; /* il manque une * pour déclarer un pointeur */ unsigned char *pnt_tbl; pnt_tbl = pnt_struct1->tableau; /* le nom est incorrect */ -
pnt_tbl = pnt_pnt_struct1->tableau[0] ?
-
-
Contributeur@Char SnipeurSalut Char Snipeur,
Non c'est mieux de mettre sans l'esperluette. C'est comme dans le cas scanf("%s", tableau); où on a char tableau[X] il ne vaut mieux pas mettre d'esperluette sinon les types ne sont plus totalement cohérents.
Cdlt, -
Contributeur@Char SnipeurHeu, je persiste.
char * ptn =&(pnt_struct1->tableau[0]) ;
ou mieux
char *ptn=pnt_struct1->tableau;
Mais si on a
char * ptn=(pnt_struct1->tableau[0]) ;
alors là je voi un problème de type.
-
-
Merci pour vos réponse !