int Add(ZGGZ tp[],int n)
{
char ch ,num[10];
int i,flag=0;//flag 标记是否已经存在
system("cls");
if(flag == 0)
{
printf("sorry, %s is already exist,try again? Y/N?",num);
scanf("%c",ch);
if (ch == 'Y'|| ch == 'y')
continue;
else return n;
编译后错误信息提示:
SalaryManager.cpp|180|warning: format '%c' expects argument of type 'char*', but argument 2 has type 'int' [-Wformat]|
解决办法:
scanf("%c",&ch);
原因:scanf里面用的是地址,不是变量名
intscanf(constchar*format,...);
|
其调用形式为: scanf("<格式说明字符串>",<变量地址>);变量地址要求有效,并且与格式说明的次序一致。
本文详细解析了在使用scanf函数时遇到的常见错误,特别是关于格式字符串与输入参数类型不匹配的问题,并提供了相应的解决策略。通过实例演示了如何正确地使用scanf函数以避免此类警告信息。

1万+

被折叠的 条评论
为什么被折叠?



