您的位置:首页 > 编程语言 > C语言/C++

[C/C++]warning: format '%c' expects argument of type 'char*', but argument 2 has type 'int' [-Wforma

2014-05-28 16:26 615 查看
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里面用的是地址,不是变量名

函数 scanf() 是从标准输入流stdin (标准输入设备,一般是键盘)中读内容的通用子程序,可以说明的格式读入多个字符,并保存在对应地址的变量中。
其调用形式为: scanf("<格式说明字符串>",<变量地址>);变量地址要求有效,并且与格式说明的次序一致。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐