ANSI C: Anonymous pointer in struct to array of strings - problems? -
i must missing obvious...
i'd have empty pointer array of strings in struct :
typedef struct scr_settext_desc_s { uint_8 value; //current value - copy made prior function call char *strings; // pointer array of strings } scr_settxt_desc;
then i'd use struct , assign real array of strings :
scr_settxt_desc scrsettxtdesc; char screensettxt_strings[4][20]; strcpy(screensettxt_strings[0], "choice1"); strcpy(screensettxt_strings[1], "choice2"); strcpy(screensettxt_strings[2], "choice3"); scrsettxtdesc.strings = screensettxt_strings;
here error :
error[pe513]: value of type "char (*)[20]" cannot assigned entity of type "char *"
what doing wrong ?
i'd use :
printf("%s",scrsettxtdesc.strings[0]);
thanks in advance,
bul.
you not creating array of strings, single string (char*).
if want have array of strings, use
char **strings;
you need initialize array using malloc
.
the error happens because limit single string 20 char ( char[20]
), incompatible char*
.
Comments
Post a Comment