C程序编译但没有输出

标签 c header-files

我正在尝试学习在 C 中创建头文件并将其包含在我的 main.c func() 中。我创建了一个简单的 tut1.c 文件,其中包含名为 call() 的函数和一个名为 call() 的外部 tut1.c 函数的 tut1.h 头文件。就是这样,现在我在 linux fedora 上使用 eclipse Juno for C/C++。我没有收到任何编译错误,但代码不会输出?我徒劳地尝试了控制台和 eclipse 。你能检查一下吗?谢谢

---main.c-----

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "tut1.h"

int main (void)

{
    int tut1(void);

    return 0;
}

-----tut1.c------

#include <stdio.h>
#include <stdlib.h>
#include "tut1.h"

int call (void)
{
    int *ptr;
    int i;

        ptr = &i;
       *ptr = 10;

    printf ("%d we are printing the value of &i\n", &i);
    printf ("%d we are printing the value of *ptr\n", *ptr);
    printf ("%d we are printing the value of ptr\n", ptr);
    printf ("%d we are printing the value of &ptr\n", &ptr);

    getchar();
    return 0;
}

----tut1.h----

#ifndef TUT1_H_
#define TUT1_H_

extern int call (void);

#endif

最佳答案

您没有看到任何内容,因为您没有从 main() 函数中调用 call() 函数。

main() 函数是您运行程序时的默认入口点,即在执行期间被调用的第一个函数。

要执行函数 call(),您需要从 main() 中调用它,如下所示:

int main (void)

{
    int result = call();

    return 0;
}

顺便说一句,int tut1(void); 在您的 main() 中的这一行只是声明了一个您似乎没有在任何地方定义的函数。所以我在上面显示的代码中删除了它。

关于C程序编译但没有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15314313/

相关文章:

c++ - c++ 中的 iostream 、 stdio.h 和 conio.h 头文件有什么区别?

c - 如果我们首先在 if 或 while 中使用 fork() 为什么会返回双零

c - GCC 优化可能产生的副作用是什么?

c - GCC 的 __attribute__((__packed__)) 是否保留原始顺序?

c - 如何在头文件中定义函数?

c++ - 为什么要先包含相关标题?

c - 我的 C 程序有什么问题?

c - 链接头文件

C++ 相互 header 包含和前向声明

c++ - Makefile - 依赖生成