0

I need something like this:

char font[128][8] = {{0}};

font[0][] = {0, 0b00000000, 0b11111100, 0b00010010, 0b00010010, 0b11111100, 0b00000000, 0};
font[1][] = {...}

But in c99 I get "expected expression before '{' token". Please help.

2
  • You can't assign to arrays. Either use initializer lists during initialization, or compound literals and memcpy(), or assign one-by-one in a loop. Commented May 9, 2013 at 11:13
  • Is 0b00000000 valid in C ?? Help please.. Commented May 9, 2013 at 11:19

3 Answers 3

1

You can only use an initialiser list ({...}) when declaring the array, that's why you're getting an error. You can't assign a value to an array, which is what font[0] is (a char[]).

You have 3 options:


  • char font[128][8] = {
      {0, 0b00000000, 0b11111100, 0b00010010, 0b00010010, 0b11111100, 0b00000000, 0};
      {...}
     }
    
  • Assign each value to an element in the array individually: font[0][0] = x, ..., font[127][7] = y (ie. using a loop).

  • memcpy blocks at a time from like a uint64_t (sizeof(font[0]) = 8) or wherever else you can neatly/efficiently store the data.

It's probably also worth noting that binary constants are a C extension, and that char is signed and if you're working with unsigned data you should probably explicitly use unsigned char.

Sign up to request clarification or add additional context in comments.

2 Comments

Wait, what? char is signed? Since when? In my version of C, whether or not char is signed is a completely implementation-defined decision.
@ElchononEdelson: Oh yeah you're right, it should be could.
0
char font[128][8] = {
    {0, 0b00000000, 0b11111100, 0b00010010, 0b00010010, 0b11111100, 0b00000000, 0},//font[0]
    /*{...}*///font[1]
};

Comments

0

Try it out :

    char font[128][8] = {{0}};  
    char a[8] = {0, 0b00000000, 0b11111100, 0b00010010, 0b00010010, 0b11111100, 0b00000000, 0};
    //Take array a to store values 

    for(int i = 0;i<8;i++)
    font[0][i] =  a[i];
    //Assign value of a to font

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.