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

来源:互联网 发布:淘宝开书店是什么类目 编辑:程序博客网 时间:2024/06/05 04:11
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("<格式说明字符串>",<变量地址>);变量地址要求有效,并且与格式说明的次序一致。

 

 

 

0 0