i have this structure:
struct dict{
int len;
char (*dict0)[MAX_WORD_LEN+1];
char (*dict1)[MAX_WORD_LEN+1];
};
and i do this:
struct dict dictionary;
struct dict *p_diction=&dictionary;
but when i try to scanf with the pointer to pointer i get an error, naturally i is defined and everything.
scanf(“%10s”,p_diction->(*(dict0+i))[0]);
‘expected identifier before ‘(‘ token
and no i dont want to scanf using &dictionary, as this also happens in other instances besides scanf.
what is the correct form to write the command?
What you want is
or
You need to pass a pointer to
charfor the%sconversion, so thechar[MAX_WORD_LEN+1]is okay (it will be converted to a pointer to the firstcharin it).gives you the pointer to the
char[MAX_WORD_LEN+1], and you want thei-th of these arrays, so you must increment this pointer byi. Then to get the right type of pointer, you must dereference to get the array. Then you can either use the automatic array-to-pointer conversion, or explicitly pass the address of the firstcharin the arrayWith the two dereferencings you attempted, you would have passed a
char, which would cause havoc. You need only one.