in something not a structure or union

K

Kodorna

im getting this msg. im starting in C and i have this:

void funcao_zera_dinamic_vet(dyna_node ** vetor)
53 {
55 if(*vetor->next!=NULL)
56 {
57 &(*vetor)->inteiro=0;
58 vetor=vetor.next;
59 funcao_zera_dinamic_vet(vetor);
60 }
61 }

and

13 struct array2
14 {
15 int inteiro;
16 struct array2 * next;
17 };
18
19 typedef struct array2 dyna_node;

Can u guys help me out?
 
A

Ancient_Hacker

Kodorna said:
im getting this msg. im starting in C and i have this:

void funcao_zera_dinamic_vet(dyna_node ** vetor)
53 {
55 if(*vetor->next!=NULL)
56 {
57 &(*vetor)->inteiro=0;

what line is the error message for?

if it's 57,

You shouldnt need the ampersand here for sure.

I think.
 
K

Kodorna

I've got it working doing:
void funcao_zera_dinamic_vet(dyna_node ** vetor)
53 {
55 if(*vetor!=NULL)
56 {
57 (*vetor)->inteiro=0;
58 vetor=&(*vetor)->next;
59 funcao_zera_dinamic_vet(vetor);
60 }
61 }

But I have some questions....
1. Why do I have to use '**' before 'vetor'?
2. When do I use '->' and '.'?

Thanx.
 
F

Fred Kleinschmidt

Kodorna said:
im getting this msg. im starting in C and i have this:

void funcao_zera_dinamic_vet(dyna_node ** vetor)
53 {
55 if(*vetor->next!=NULL)

vetor is of type 'dyna_node **'
What do you pass into funcao_zera_dinamic_vet when you call it?
Is it a 2-dimension array? the address of a dyna_node pointer?

Perhaps you mean here: (*vetor)->next ?
56 {
57 &(*vetor)->inteiro=0;

Do you mean (*vetor)->inteiro = 0 ?
 
A

Ancient_Hacker

Kodorna wrote:

1. Why do I have to use '**' before 'vetor'?

This is too hard to explain in this little white box. Apparently
what's coming in is a pointer to a pointer to the struct. Which means
in the function you'll have to put a * in front of the vetor to refer
to the pointer, or two stars to refer to the value, or one star in
front and a -> in back to refer to a field. Confusing, isnt it.

2. When do I use '->' and '.'?

a->b is just shorthand for (*a).b
 
C

CBFalconer

Ancient_Hacker said:
what line is the error message for?

if it's 57,

You shouldnt need the ampersand here for sure.

I think.

I think he should either have:

(*vetor).inteiro = 0;
or
vetor->inteiro = 0; /* the more usual phrasing */
 
J

Joe Estock

CBFalconer said:
I think he should either have:

(*vetor).inteiro = 0;
or
vetor->inteiro = 0; /* the more usual phrasing */

Not quite. vetor is defined as "dyna_node ** vetor" so the dereferencing
is needed in this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top