Use pointer to struct

0

I wanted to know how to access a certain element of a struct in the way I'm defining it. Here is my struct:

typedef struct {

 char *produtos[200000];
 int contador;

} Produtos,*ProdutosP;

I set ProdutosP p as a pointer to the struct. I added the first string of char *produtos[200000] using p->produtos[0] but I wanted to access the first string of the first string. How do I get it?

    
asked by anonymous 20.03.2016 / 19:08

2 answers

1
  

I used the first string of char *produtos[200000] using p->produtos[0] but I wanted to access the first string of the first string.

p->produtos[0][0]

or

*(p->produtos[0])
    
20.03.2016 / 19:59
1

You have defined products as an array of string pointers. To access the first character you only have to use one more [] In this case p->produtos[0][0] . The first number between parentheses is the string and the second character.

That is, the number in brackets dereferencing the string at position n and the second character in the chosen position.

The link I added is in English if you prefer to have one in Spanish at wikipedia.

    
20.03.2016 / 19:53