【发布时间】:2017-08-05 18:39:57
【问题描述】:
我想删除警告而不将数据类型更改为 char。
#include<stdio.h>
#include<stdlib.h>
main()
{
unsigned char ch;
printf("Hello This is Problematic\n");
scanf("%d",&ch);
printf("1\n");
}
这会产生警告
test.c:7:2: 警告:格式 '%d' 需要类型为 'int *' 的参数,但参数 2 的类型为 'unsigned char *' [-Wformat=] scanf("%d",&ch );
【问题讨论】:
-
你想达到什么目的?这是关于您的程序中存在严重错误的警告。程序的整个行为是未定义的。
-
%d-->"%hhu"or%c,main()-->int main(void) -
scanf 到 int,然后检查长度并复制到 char
标签: c scanf compiler-warnings