【发布时间】:2016-01-21 02:38:37
【问题描述】:
我试图学习一些基本的 c 代码,以提高我的一般技能。我写了一个基本脚本,告诉我一个数字是大于还是小于 10:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main()
{
int number;
printf("Enter an integer\n");
scanf("%d",&number);
printf("Integer entered by you is %d\n", number);
if ( "%d" > 10)
printf("%d is greater than 10.\n", number);
else
printf("%d is less than 10.\n", number);
return 0;
}
然而,当我编译它时,我得到一个错误,指出我正在尝试比较一个指针和一个整数:
dave@dave-[laptop]:~/Code/C/Examples$ gcc 004----takeandif.c -o 004----takeandif
004----takeandif.c: In function ‘main’:
004----takeandif.c:16:14: warning: comparison between pointer and integer [enabled by default]
if ( "%d" > 10)
^
当我运行它时,它说所有数字都小于 10:
dave@dave-[laptop]:~/Code/C/Examples$ ./004----takeandif
Enter an integer
2
Integer entered by you is 2
2 is greater than 10.
其他答案均不适用于我的情况。我应该改变什么?
【问题讨论】:
-
if ( "%d" > 10)你觉得有什么作用?
标签: c compilation compiler-errors ubuntu-14.04 compiler-warnings