Problem with an array of char pointers

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
zx81ultra
Member
Posts: 38
Joined: Thu Feb 13, 2020 1:56 am

Problem with an array of char pointers

Post by zx81ultra »

Hello,

I'm struggling with this:

Code: Select all

const char *LevelMap[][] = {
{1,3,3,1,1,0},
{1,28,3,-1,1,3,9,12,21,12,0},
{1,8,2,1,1,3,9,12,21,12,4,15,7,15,17,0}
};

char Value;

Value = LevelMap[1][1]; // Value should be 28
My idea was to have an array of char pointers pointing to variable length char vector. Any idea on how to do that ?

Thank you !
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

We're definitely missing a diagnostic here - I'll add one in when I'm back from my travels.

Running the code through clang gives this:

array2.c:3:20: error: array has incomplete element type 'const char []'

Which means that the size of the second dimension should be defined, LevelMap[][20] for example.
zx81ultra
Member
Posts: 38
Joined: Thu Feb 13, 2020 1:56 am

Post by zx81ultra »

I think my declaration is incorrect and won't work with variable length arrays.

I had to convert it into an array of pointers to strings and it is working now:

Code: Select all

const char *LevelMap[25] = {
"133110",
"1L3Z139<E<0",
"1821139<E<4?7?A0",
"1L5Z1396G639<G<39BGB4868B0",
...
...
Thank you !
Post Reply