wrote:
>
> I got errors:
> qu2-1.c:66: warning: format '%s' expects type 'char *', but argument 2
> has type 'char (*)[19u]'
> qu2-1.c:72: warning: format '%s' expects type 'char *', but argument 2
> has type 'char (*)[19u]'
>
> but I don't quite know what it means...
> <code/>
> struct details {
> int id;
> char forename[20];
> struct details patient[MAXPATIENTS];
> int npatients = 0;
> scanf("%s", &patient[index].forename);
(patient[index].forename) is the name of an array of 20 char.
(array of 20 char) is the type of the expression.
An expression of array type, converts to a pointer to its first element
in all but three cases. So,
scanf("%s", patient[index].forename);
is the right way to write that.
(&patient[index].forename) is the address of an array of 20 char.
(pointer to an array of 20 char) is the type of the expression.
When the name of an array is the operand of the & operator,
is one of the cases where the name of an array doesn't
automatically convert to a pointer.
When it's the operand of sizeof is another case
where the name of an array doesn't
automatically convert to a pointer.
The third case, is when a string literal initializes an array.
--
pete