Abit OT, need help with functions - Xwindows

This is a discussion on Abit OT, need help with functions - Xwindows ; Hi, I know this is off topic, but this is the best place where I figured I'ld get an answer Why doesn't this work ?? void fnc (off) struct mystructure *off; { printf("Changeing var to 123"); &off.somefield = 123 ; ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Abit OT, need help with functions

  1. Abit OT, need help with functions


    Hi, I know this is off topic, but this is the best place where I figured
    I'ld get an answer




    Why doesn't this work ??

    void fnc (off)
    struct mystructure *off;
    {
    printf("Changeing var to 123");
    &off.somefield = 123 ;
    return ;
    }
    int main(){
    struct mystructure off;
    func(&mystructure);
    printf("Returned %d\n",off.somefield);
    exit(1);
    }


  2. Re: Abit OT, need help with functions



    Adam Dickson wrote:
    >
    >
    > Hi, I know this is off topic, but this is the best place where I figured
    > I'ld get an answer
    >
    > Why doesn't this work ??
    >
    > void fnc (off)
    > struct mystructure *off;
    > {
    > printf("Changeing var to 123");
    > &off.somefield = 123 ;


    "off" is a pointer to a struct. You need to dereference the pointer,
    not
    use its address. Try:

    off->somefield = 123

    > return ;
    > }
    > int main(){
    > struct mystructure off;
    > func(&mystructure);
    > printf("Returned %d\n",off.somefield);
    > exit(1);
    > }


    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Common User Interface Services
    M/S 2R-94 (206)544-5225

  3. Re: Abit OT, need help with functions



    Adam Dickson wrote:
    >
    >
    > Hi, I know this is off topic, but this is the best place where I figured
    > I'ld get an answer
    >
    > Why doesn't this work ??
    >
    > void fnc (off)
    > struct mystructure *off;
    > {
    > printf("Changeing var to 123");
    > &off.somefield = 123 ;


    No - you want:
    off->somefield = 123;

    > return ;
    > }
    > int main(){
    > struct mystructure off;
    > func(&mystructure);


    No - you want:
    func( &off );

    > printf("Returned %d\n",off.somefield);
    > exit(1);
    > }


    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Common User Interface Services
    M/S 2R-94 (206)544-5225

+ Reply to Thread