我正在为学校做一个项目,这个警告一直困扰着我。 我的代码有什么问题?
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);
还有一个警告:
warning: format '%d' expects argument of type 'int', but argument 10 has type 'char *' [-Wformat]
我不知道该怎么办
最佳答案
您的 fprintf
调用有 8 个格式说明符,但传递了 9 个进一步的参数来填充它们。
第8个格式说明符是%d
;与此对应的参数是 Item[i]->Name
。警告告诉您 Item[i]->Name
是一个字符串,因此不能(不应该)转换为有符号整数。
我假定 Item[i]->Price
的类型为 int
;然后您需要向您的格式字符串添加一个额外的 %s
(%d
之前的任何位置)或删除其中一个字符串参数。
关于c - 格式参数太多 [-Wformat-extra-args],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17091746/