2017-08-17 59 views
-1

出于某种原因,我看不到我的代码出现错误。看不到错误

#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

'的scanf( “%S”,&age);'这是一个在'int'使用'%D'转来转去你的编译器警告修改为迂腐级别并将它们视为错误现代编译器将标记关于格式说明符不匹配的警告与提供的参数有关的内容 – WhozCraig

+0

'age'是一个'int',而不是一个字符串,尝试'scanf(“%d “,&age);' – yano

回答

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); 
     ^
$