2017-08-17 13 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'です。 "、&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); 
     ^
$ 
関連する問題