How to set 1d array to 2d array element in C -


i need this:

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

but in c99 "expected expression before '{' token". please help.

you can use initialiser list ({...}) when declaring array, that's why you're getting error. can't assign value array, font[0] (a char[]).

you have 3 options:


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

  • memcpy blocks @ time uint64_t (sizeof(font[0]) = 8) or wherever else can neatly/efficiently store data.

it's worth noting binary constants c extension, and char signed , if you're working unsigned data should explicitly use unsigned char.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -