无法看到错误

时间:2017-08-17 23:16:59

标签: c if-statement

出于某种原因,我无法看到我的代码出错的地方。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int age;

    printf("How old are you \n");

    scanf("%s", &age);

    if (age > 18){
        printf("You may enter \n");
    }
 /* this above is all that my program runs, always prints "You may enter"*/
  if (age < 18){
        printf("Nothing to see here \n");
    }

    return 0;
}

/ 感谢 /

1 个答案:

答案 0 :(得分:1)

提示:

$ gcc main.c                                                                   
main.c: In function ‘main’:
main.c:10:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int *’ [-Wformat=]
     scanf("%s", &age);
           ^
$