in something not a structure or union

Discussion in 'C Programming' started by Kodorna, Oct 26, 2006.

  1. Kodorna

    Kodorna Guest

    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?
     
    Kodorna, Oct 26, 2006
    #1
    1. Advertising

  2. Kodorna wrote:
    > 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.
     
    Ancient_Hacker, Oct 26, 2006
    #2
    1. Advertising

  3. Kodorna

    Kodorna Guest

    58 too...

    Ancient_Hacker wrote:
    >
    > if it's 57,
    >
    > You shouldnt need the ampersand here for sure.
    >
    > I think.
     
    Kodorna, Oct 26, 2006
    #3
  4. Kodorna

    Kodorna Guest

    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.
     
    Kodorna, Oct 26, 2006
    #4
  5. "Kodorna" <> wrote in message
    news:...
    > 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 ?

    > 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?
    >
     
    Fred Kleinschmidt, Oct 26, 2006
    #5
  6. 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
     
    Ancient_Hacker, Oct 26, 2006
    #6
  7. Kodorna

    CBFalconer Guest

    Ancient_Hacker wrote:
    > Kodorna wrote:
    >
    >> 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.


    I think he should either have:

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

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.

    <http://cbfalconer.home.att.net>
     
    CBFalconer, Oct 27, 2006
    #7
  8. Kodorna

    Joe Estock Guest

    CBFalconer wrote:
    > Ancient_Hacker wrote:
    >> Kodorna wrote:
    >>
    >>> 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.

    >
    > 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.
     
    Joe Estock, Oct 27, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Garman
    Replies:
    1
    Views:
    680
    Matt Garman
    Apr 25, 2004
  2. Jeff Massung

    Setting union member in structure

    Jeff Massung, Dec 22, 2003, in forum: C++
    Replies:
    2
    Views:
    489
    Jeff Massung
    Dec 22, 2003
  3. Peter Dunker

    union in struct without union name

    Peter Dunker, Apr 26, 2004, in forum: C Programming
    Replies:
    2
    Views:
    910
    Chris Torek
    Apr 26, 2004
  4. Replies:
    8
    Views:
    357
  5. deepak
    Replies:
    12
    Views:
    1,954
    Keith Thompson
    May 9, 2008
Loading...

Share This Page