如何在Code :: Blocks中添加另一个C文件 [英] How to add another C file in Code::Blocks

查看:343
本文介绍了如何在Code :: Blocks中添加另一个C文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的老师希望将我的项目的函数原型和typedefs存储在一个单独的.c文件中。

这样main.c有工作要做,another.c具有protypes和typedefs,并且

so my teacher wants the function prototypes and typedefs for my project stored in a separate .c file.
so main.c has the stuff to do, another.c has the protypes and typedefs, and another.h has the declarations.

我该怎么做?我正在使用GNU GCC编译器,因为这似乎是编译器特有的问题。我在尝试gcc another.c,但是编译器无法识别gcc,所以我认为我做错了。

how can i do this? i am using GNU GCC compiler because it seems like this is a compiler specific issue. i was trying gcc another.c but the compiler doesn't recognize the gcc so i think I'm doing it wrong.

我感觉好密集....我整个项目都运行良好,但是应该在另一个项目中的所有内容都在另一个项目中。h....

i feel so dense.... i have the entire project working good but everything that's supposed to be in the another.c is in the another.h....

谢谢

推荐答案

main.c如下所示:

The main.c will look something like this:

// bring in the prototypes and typedefs defined in 'another' 
#include "another.h"

int main(int argc, char *argv[])
{
    int some_value = 1;

    // call a function that is implemented in 'another' 
    some_another_function(some_value);
    some_another_function1(some_value);
    return 1;        
}

another.h应该包含在其中找到的函数的typedef和函数原型another.c文件:

The another.h should contain the typedefs and function prototypes of the functions found in another.c file:

// add your typdefs here

// all the prototypes of public functions found in another.c file
some_another_function(int some_value);
some_another_function1(int some_value);

another.c应该包含在another.h中找到的所有函数原型的函数实现。 / p>

The another.c should contain the function implementations of all the function prototypes found in another.h:

// the implementation of the some_another_function
void some_another_function(int some_value)
{
    //....
}

// the implementation of the some_another_function1
void some_another_function1(int some_value)
{
    //....
}

这篇关于如何在Code :: Blocks中添加另一个C文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆