|
10鱼币
C语言的c99标准不是增加了_Bool么,那么在用scanf输入时应该用哪个格式符?
我试了,不是 %d和%c
c99应该引入了新的格式符吧(话说%d、%c这是叫格式符吧)
百度也找不到结果
- #include <stdio.h>
- #include <stdbool.h>
- int main(void)
- {
- bool flag;
- scanf("%c", &flag);
- return 0;
- }
复制代码- main.c:7:10: warning: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘_Bool *’ [-Wformat=]
复制代码
- #include <stdio.h>
- #include <stdbool.h>
- int main(void)
- {
- bool flag;
- scanf("%d", &flag);
- return 0;
- }
复制代码- main.c:7:10: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘_Bool *’ [-Wformat=]
复制代码
没办法的,不过可以用0或1 来代替
- #include <stdbool.h>
- #include <stdio.h>
- bool b;
- int temp;
- scanf("%d", &temp);
- b = temp;
复制代码
|
|