C 错误 : comparison between pointer and integer [enabled by default]

标签 c compilation compiler-errors ubuntu-14.04 compiler-warnings

我正在尝试学习一些基本的 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)

if( number > 10 )

关于C 错误 : comparison between pointer and integer [enabled by default],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34914445/

相关文章:

java - 在 Windows 命令行中将 Jar 文件添加到构建路径

java - 导入的包编译后是否包含在.class文件中?

Python Class() 没有参数错误。我正在使用 self

android - TabWidget.OnTabSelectionChanged无法解析为一种类型

c - 使用变量概率影响 rand() 的输出

c - 为什么存储在整数中的字符串会被打印出来?

C:通过在函数中转换 void 指针来声明不同的类型

python - 在C中,是否可以通过重新编译动态库来将新代码集成到正在运行的进程中?

parsing - 判断文法是否为LR(0)

c# - C#存储对List <T>的引用