Jump to content

Estruturas e "->"


x3minater

Recommended Posts

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

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.

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.