Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
由于某种原因,我看不到我的代码有问题。

#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;
}


/谢谢/

最佳答案

暗示:

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

关于c - 看不到错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45746254/

10-09 08:46