Copying strings to character array

Posted By: trader6363

Copying strings to character array - 12/14/15 17:21

When I run the following code it returns "pointer expected" error.
function main(){
static char a[2][500];
strcpy(a[0],"string");
strcpy(a[1],"string1");
printf("%s %s",a[0],a[1]);
}

Anyway to copy strings to a 2 dimension character array so that I can later retrieve them by referencing the first dimension of that array?
Posted By: jcl

Re: Copying strings to character array - 12/15/15 09:17

No, but you can either define a struct containing your 500 chars array, or simply:

char a[1000];
strcpy(a+0*500,"string0");
strcpy(a+1*500,"string1");
© 2024 lite-C Forums