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

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() 是从 标准输入流stdin (标准输入设备,一般是键盘)中读内容的通用 子程序,可以说明的格式读入多个字符,并保存在对应地址的变量中。
其调用形式为: scanf("<格式说明字符串>",<变量地址>);变量地址要求有效,并且与格式说明的次序一致。

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值