1

Im trying to assign a array to my letter.charData but i get this error:

IntelliSense: expression must be a modifiable lvalue

Im trying to add my array arr to letter.charData

Thanks in advance!

struct _Letter{
    char character;
    int width;
    int charData[8][5];
};

typedef struct _Letter Letter;

Letter *allocLetter(void)
{
    Letter *letter;

    letter = (Letter*) malloc(1 * sizeof(Letter));

    letter->character = NULL;
    letter->width = NULL;

    /* charData? */

    return letter;
}

int main(void)
{ 
    Letter letter = *allocLetter();

    int arr[8][5] = 
    {
        0,0,0,0,0,
        1,0,0,0,0,
        1,0,0,0,0,
        1,0,0,0,0,
        1,0,0,0,0,
        1,0,0,0,0,
        1,0,0,0,0,
        1,0,0,0,0
    };

    letter.character = '1';
    letter.charData = arr;

    return(0);
}
2
  • 1
    I'm not sure, but I think _L... is reserved. Name it Letter_ or something. Commented Dec 6, 2011 at 11:42
  • why don't you instead pass arr to the allocLetter together with the character e.g. Letter* allocLetter( int **arr, char ch ) and then initialize it in there by copying it into the struct. Commented Dec 6, 2011 at 11:50

1 Answer 1

5

_Letter::charData is an array, not a pointer, so you can't just assign another array to it. Either copy arr's contents into it with memcpy, or change its type to a pointer:

typedef struct {
    char character;
    int width;
    int (*charData)[5];
} Letter;

Also,

  1. Identifier names shouldn't start with _ followed by a capital
  2. NULL should only be used for pointers; use '\0' for characters, plain 0 for integers
  3. You don't check the return value of malloc for null
  4. You're not freeing allocated memory.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.