Reputation: 61
Im doing a project for school and this is the warning that keeps bugging me. Whats wrong with my code?
fprintf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%d\n", Item[i]->ID, Item[i]->Date, Item[i]->Adress,
Item[i]->Street number, Item[i]->Postal Code,
Item[i]->City, Item[i]->Phone,Item[i]->Name,
Item[i]->Price);
Also there is another warning:
warning: format '%d' expects argument of type 'int', but argument 10 has type 'char *' [-Wformat]
I don't know what to do
Upvotes: 3
Views: 100183
Reputation: 1
Your fprintf call has 8 format specifiers but passes 9 further arguments to fill these.
The 8th format specifier is %d; the argument corresponding to this is Item[i]->Name. The warning is telling you that Item[i]->Name is a string so can't (shouldn't) be converted to a signed integer.
I presume Item[i]->Price has type int; you then either need to add an extra %s to your format string (anywhere before the %d) or remove one of the string arguments.
Upvotes: 0
Reputation: 42165
Your fprintf
call has 8 format specifiers but passes 9 further arguments to fill these.
The 8th format specifier is %d
; the argument corresponding to this is Item[i]->Name
. The warning is telling you that Item[i]->Name
is a string so can't (shouldn't) be converted to a signed integer.
I presume Item[i]->Price
has type int
; you then either need to add an extra %s
to your format string (anywhere before the %d
) or remove one of the string arguments.
Upvotes: 9