Results 1 to 2 of 2

Thread: struct

  1. #1
    Join Date
    Apr 2004

    Exclamation Unanswered: problems with struct

    Hi the following is the struct format:
    typedef struct iorb {

    short base_pri;
    struct iorb *link;
    char filler[110];

    } IORB;

    I try to assign a string to base_pri, the code I used as followed
    temp->filler=filler3;However it shows the error code like this
    " temp->filler=filler3;is not an lvalue, but occurs in a context that requires one. (needlvalue)" So what is the problem with it?

    I did declare IORB *temp and char filler3[110];
    when I compile, it shows me a message could you please help me to solve this problem.

    Last edited by fj8283888; 04-12-04 at 11:18.

  2. #2
    Join Date
    Apr 2002
    As you know C usually handles strings as char arrays.
    The = operator can only be used to assign basic data types like char, integer and float. The -> operator is used to dereference a pointer within a struct ( struct->pointer is equal to *(struct.pointer) ).
    You are trying to assign the address of the first element of your filler3 array the value of the first element of the temp.filler array. Depending on what you want to do in your program you either need to assign the pointers, e.g. temp.filler = filler3 or you need to copy all elements of the arrays, e.g. strcpy(temp.filler, filler3).

    edit: typo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts