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 @ timeuint64_t
(sizeof(font[0]) = 8
) or wherever else can neatly/efficiently store data.
it's worth noting binary constants c extension, and , if you're working unsigned data should explicitly use char
signedunsigned char
.
Comments
Post a Comment