Creating an array of strings

Posted By: trader6363

Creating an array of strings - 07/02/15 16:11

Hi
I would like to create a 2d array that hold strings, however I cant figure out how to do this in lite-c. In c I can do something like this:
char a[2][10];
strcpy(a[0], "123456789");
strcpy(a[1], "hello");

Thanks
Posted By: jcl

Re: Creating an array of strings - 07/03/15 13:24

Your array holds chars, not strings. Strings are char pointers.

For strings:

string a[2];
a[0] = "123456789";
a[1] = "hello";

For chars:

static char a[20];
strcpy(a,"123456789");
strcpy(a+10,"hello");
Posted By: trader6363

Re: Creating an array of strings - 07/03/15 16:16

Wow, I spent hours over complicating this and the answer is so simple. Thanks!
© 2024 lite-C Forums