x3minater Posted January 2, 2008 at 07:26 PM Report Share #157477 Posted January 2, 2008 at 07:26 PM Boas, tenho aqui uma duvida... Se tivermos uma estrutura dentro de outra estrutura, por exemplo: struct blabla { int n; int i; struct blabla_in { char dig[5+1]; int quant; } struct blabla *prox; } Se nos refericemos ao n ou ao i num printf("...%d...", ...) seria: walker->i ou walker->n, certo? (Sendo walker uma variavel do tipo: struct blabla) Mas como é que nos referimos ao dig[5+1] e ao quant num printf??? Da mesma maneira? EDIT: E será que tenho de por: "struct blabla_in *prox" para os elementos estarem ligados em forma de lista??? Link to comment Share on other sites More sharing options...
Rui Carlos Posted January 2, 2008 at 07:41 PM Report Share #157481 Posted January 2, 2008 at 07:41 PM Será walker->i se walker for do tipo struct blabla *. Penso que essa declaração está errada, devia ser qualquer coisa como: struct blabla { int n; int i; struct blabla_in { char dig[5+1]; int quant; } in; struct blabla *prox; }; Assim, poderias aceder ao quant fazendo walker->in.quant. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
x3minater Posted January 2, 2008 at 07:47 PM Author Report Share #157482 Posted January 2, 2008 at 07:47 PM Será walker->i se walker for do tipo struct blabla *. sim, tinha me eskecido de dizer... Assim, poderias aceder ao quant fazendo walker->in.quant. Não teria que fazer: typedef struct blabla_in { char dig[5+1]; int quant; } in; ?? E se quisesse aceder a dig[5+1]?? Seria: walker->in.dig ou walker->in.dig[5+1]. Link to comment Share on other sites More sharing options...
Rui Carlos Posted January 2, 2008 at 07:56 PM Report Share #157483 Posted January 2, 2008 at 07:56 PM dig[5+1] não existe. Apenas existe dig[0], dig[1], ..., dig[5]. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
x3minater Posted January 3, 2008 at 11:34 PM Author Report Share #157731 Posted January 3, 2008 at 11:34 PM Ja agr...em vez de estar a abrir outro topico... Podemos passar uma string, de uma estrutura, para um vector de strings? EX: struct bla { char descr [70+1]; struct produtos *prox; } typedef struct bla BLA; BLA *walker; int v[10]; int i; for(i=0; i<10; i++){ n=0; walker2->descr = v[n++]; } Pode-se fazer isso? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now