c - 为什么我不能用 dev c 编译简单的项目

标签 c

我不知道为什么开发人员无法编译下面的简单项目。

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); 即可使您的程序正常运行。

https://linux.die.net/man/3/scanf

关于c - 为什么我不能用 dev c 编译简单的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51571080/

相关文章:

c - 坚持这个C代码

c++ - 如何在双向图中找到两条不相交的路径?

c - 如何读取文本文件 C 中矩阵的大小

c - 如何将数组包含到 C 函数定义中

java - 将位修改代码从 C 移植到 Java

c++ - 为什么使用 _access 时只读测试对读写文件有效?

c - 从文件填充数组

Python 和 C 耦合

c - 将制表符分隔的数据读取到 C 中的数组

c - 此代码不可移植或不安全