我不知道为什么开发人员无法编译下面的简单项目。
error: Project1.exe has stopped working.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int n,d;
while(1){
printf("enter number");
scanf("%d",n);
d=n%10;
while(d!=0){
n=n/10;
printf("%d",d);
d=n%10;
}
}
return 0;
}
最佳答案
首先,您的项目确实可以编译,因为您收到了运行时错误。
发生运行时错误是因为您没有正确使用scanf
。格式字符串后面的 scanf 参数应该是指向变量的指针。
我不知道您使用的是哪个编译器,但是任何相当现代的编译器都会向您发出有关此问题的编译器警告,例如这是 Clang 的输出:
apa.c:9:20: warning: format specifies type 'int *' but the argument has type 'int' [-Wformat]
scanf("%d",n);
~~ ^
将其更改为 scanf("%d",&n);
即可使您的程序正常运行。
关于c - 为什么我不能用 dev c 编译简单的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51571080/