I write a code to store patterns for LED blinking, but I got this error:
led_basics:39: error: cannot convert 'char (*)[17][2]' to 'char*' in initialization
led_basics:39: error: cannot convert 'char (*)[16][2]' to 'char*' in initialization
led_basics:39: error: cannot convert 'char (*)[13][2]' to 'char*' in initialization
and so on for all pattern. How can I fix it? Here is the code:
char nulla[17][2]={{0,127},{8,125},{9,121},{10,113},{12,97},{14,65},{24,67},{27,71},{28,70},{30,78},{32,76},{36,88},{40,80},{42,112},{48,96},{56,64},{68,0}};
char egy[16][2]={{0,0},{9,4},{16,6},{18,2},{21,3},{27,7},{28,6},{30,14},{32,12},{36,24},{40,16},{42,48},{48,32},{51,96},{56,64},{68,0}};
char ketto[13][2]={{0,98},{7,99},{8,97},{12,113},{14,81},{20,89},{21,88},{24,74},{27,78},{30,70},{32,68},{36,64},{68,0}};
char harom[17][2]={{0,34},{7,35},{8,33},{10,41},{14,9},{17,73},{21,72},{24,74},{27,78},{30,70},{32,68},{36,80},{42,112},{48,96},{51,32},{56,0},{68,0}};
char negy[17][2]={{0,7},{7,6},{8,4},{9,0},{10,8},{21,9},{24,11},{27,15},{28,14},{32,12},{36,24},{40,16},{42,48},{48,32},{51,96},{56,64},{68,0}};
char ot[14][2]={{0,39},{8,37},{9,33},{10,41},{14,9},{17,73},{28,72},{30,64},{36,80},{42,112},{48,96},{51,32},{56,0},{68,0}};
char hat[17][2]={{0,62},{7,63},{8,61},{9,57},{12,41},{14,9},{17,73},{21,72},{24,74},{30,66},{32,64},{36,80},{42,112},{48,96},{51,32},{56,0},{68,0}};
char het[15][2]={{0,7},{8,5},{9,1},{24,3},{27,7},{28,6},{30,14},{32,12},{36,24},{40,16},{42,48},{48,32},{51,96},{56,64},{68,0}};
char nyolc[15][2] = {{0,127},{8,125},{9,121},{12,105},{14,73},{24,75},{27,79},{28,78},{32,76},{36,88},{40,80},{42,112},{48,96},{56,64},{68,0}};
char kilenc[13][2] = {{0,79},{8,77},{9,73},{24,75},{27,79},{28,78},{32,76},{36,88},{40,80},{42,112},{48,96},{56,64},{68,0}};
char kettospont[6][2] = {{0,0},{9,4},{12,20},{18,16},{24,0},{68,0}};
char *karakterek[11]={&nulla,&egy,&ketto,&harom,&negy,&ot,&hat,&het,&nyolc,&kilenc,&kettospont};
2 Answers 2
karakterek is an array of char pointers. It cannot be used to store pointers to char arrays.
I'm not sure it would be possible to store pointers to your 2 dimensional arrays since they are all of different dimensions. Someone else might know a way to do that.
Here's how I would do it (using as similar as possible a structure):
char nulla[]={0,127,8,125,9,121,10,113,12,97,14,65,24,67,27,71,28,70,30,78,32,76,36,88,40,80,42,112,48,96,56,64,68,0};
char egy[]={0,0,9,4,16,6,18,2,21,3,27,7,28,6,30,14,32,12,36,24,40,16,42,48,48,32,51,96,56,64,68,0};
char ketto[]={0,98,7,99,8,97,12,113,14,81,20,89,21,88,24,74,27,78,30,70,32,68,36,64,68,0};
char harom[]={0,34,7,35,8,33,10,41,14,9,17,73,21,72,24,74,27,78,30,70,32,68,36,80,42,112,48,96,51,32,56,0,68,0};
char negy[]={0,7,7,6,8,4,9,0,10,8,21,9,24,11,27,15,28,14,32,12,36,24,40,16,42,48,48,32,51,96,56,64,68,0};
char ot[]={0,39,8,37,9,33,10,41,14,9,17,73,28,72,30,64,36,80,42,112,48,96,51,32,56,0,68,0};
char hat[]={0,62,7,63,8,61,9,57,12,41,14,9,17,73,21,72,24,74,30,66,32,64,36,80,42,112,48,96,51,32,56,0,68,0};
char het[]={0,7,8,5,9,1,24,3,27,7,28,6,30,14,32,12,36,24,40,16,42,48,48,32,51,96,56,64,68,0};
char nyolc[] = {0,127,8,125,9,121,12,105,14,73,24,75,27,79,28,78,32,76,36,88,40,80,42,112,48,96,56,64,68,0};
char kilenc[] = {0,79,8,77,9,73,24,75,27,79,28,78,32,76,36,88,40,80,42,112,48,96,56,64,68,0};
char kettospont[] = {0,0,9,4,12,20,18,16,24,0,68,0};
char* karakterek[]={nulla,egy,ketto,harom,negy,ot,hat,het,nyolc,kilenc,kettospont};
For starters, I'd make the char arrays single dimension. Since the 2nd dimension is always a size of 2, you could index through your values reading index 0 into x0, index 1 to y0, index 2 to x1 and index 3 to y1 (I'm assuming these are x y co-ordinate pairs).
Secondly, I'd lose the hard-coded sizes for the arrays. If you want to add or remove entries, you don't have to keep updating the sizes.
Finally, I'd lose the '&' from your array of array pointers. Referring to an array simply by its name gives you a pointer to it. I think '&' gives you a pointer to the pointer, but I could be wrong.
As the second dimension is always 2, you can do this:
typedef char Tuple[2];
Tuple nulla[17] = {{0,127},{8,125},{9,121},{10,113},{12,97},{14,65},{24,67},{27,71},{28,70},{30,78},{32,76},{36,88},{40,80},{42,112},{48,96},{56,64},{68,0}};
Tuple egy[16] = {{0,0},{9,4},{16,6},{18,2},{21,3},{27,7},{28,6},{30,14},{32,12},{36,24},{40,16},{42,48},{48,32},{51,96},{56,64},{68,0}};
Tuple ketto[13] = {{0,98},{7,99},{8,97},{12,113},{14,81},{20,89},{21,88},{24,74},{27,78},{30,70},{32,68},{36,64},{68,0}};
// etc.
Tuple* karakterek[3] = {nulla, egy, ketto}; // etc.
(The typedef
makes it easier.)