多个文件 [英] Multiple files

查看:47
本文介绍了多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于多个文件的一个简单问题。


假设我有以下内容:


#include< stdio。 h>


无效标题(无效);


int main(无效)

{

printf(" Hello。我要打电话给我的标题()函数\ n \\ n \\ nn;);

标题();

printf(现在我回到了内部\,主要是。。\ n);

返回0;

}


无效标题(无效)

{

printf(" Hello!您目前位于标题()内);

printf(" function.\\\
);

}


如何将其拆分为单独的文件?我需要一个标题

文件(.h)和一个单独的(.c)文件以及主(.c)文件

有main()它的作用是什么?


会去哪里?

谢谢!


fb寻找他失踪的C书......

解决方案

2003年9月2日星期二09:53:19 GMT

fb < me@no.net>写道:

什么会去哪里?
谢谢!




它可以全部在同一目录中:


headingheader.h:

void Heading(void);


mainfile.c:

#include< stdio.h>


#include" headingheader.h"


int main(无效)

{

printf(你好。我要打电话给我的标题()函数\ n \\ n \\ n;);

标题() ;

printf(现在我回到了内部\,主要是。和。);

返回0;

}


headingfile.c:

#include< stdio.h>


#include" headingheader.h"


void标题(无效)

{

printf(" Hello!你是目前位于Heading()");

printf(" function.\ n);

}


-

char * x(c,k,s)char * k,* s; {if (!k)return * s-36?x(0,0,s + 1):s; if(s)if(* s)c = 10 +(c?(x(

c) ,k,0),x(c,k + = * sc,s + 1),* k):( x(* s,k,s + 1),0));否则c = 10; printf(&) x(~0,0,k)[c-〜 -

c +1[〜c< -c]],c);} main(){x(0,& ; ^ [kXc6] dn_eaoh


%C"," -34 * 1 '' +(,03#+)。/ '' /// *"); }


fb< me@no.net>写在< jM ******************** @ news1.calgary.shaw.ca>:

一个简单的问题关于多个文件。

让我们说我有以下内容:

#include< stdio.h>

无效标题(无效) );

int main(无效)
{
printf(" Hello。我要打电话给我的Heading()函数\ n \ nn) ;
标题();
printf("现在我回到了内部\main \"。\ n");
返回0;
}

void标题(无效)
{
printf(" Hello!您目前位于标题()内);
printf(" function.\\\
;
}

如何将其拆分为单独的文件?除了包含main()函数的main(.c)文件之外,我还需要一个标题
文件(.h)和一个单独的(.c)文件吗?
确实。

什么会去哪里?
你想把原型放在一个头文件中(例如''heading.h''),

你在''main.c''中#include,然后放入函数声明在

单独的.c文件中(例如''heading.c''),然后编译并链接两者。

谢谢!



祝你好运! :)


Irrwahn

-

空气是带水洞的水。


One quick question about multiple files.

Let''s say I had the following:

#include <stdio.h>

void Heading(void);

int main(void)
{
printf("Hello. I''m about to call my Heading() function\n\n");
Heading();
printf("Now I''m back inside \"main\".\n");
return 0;
}

void Heading(void)
{
printf("Hello! You are currently inside the Heading() ");
printf("function.\n");
}

How would I split this up into seperate files? Would I need a header
file (.h) and a seperate (.c) file in addition to the main (.c) file
that has the main() function in it?

What would go where?
Thanks!

fb goes looking for his missing C book...

解决方案

On Tue, 02 Sep 2003 09:53:19 GMT
fb <me@no.net> wrote:

What would go where?
Thanks!



It could go all in the same directory:

headingheader.h:
void Heading(void);

mainfile.c:
#include <stdio.h>

#include "headingheader.h"

int main(void)
{
printf("Hello. I''m about to call my Heading() function\n\n");
Heading();
printf("Now I''m back inside \"main\".\n");
return 0;
}

headingfile.c:
#include <stdio.h>

#include "headingheader.h"

void Heading(void)
{
printf("Hello! You are currently inside the Heading() ");
printf("function.\n");
}

--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k):(x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh


%c","-34*1''.+(,03#;+,)/''///*");}


fb <me@no.net> wrote in <jM********************@news1.calgary.shaw.ca>:

One quick question about multiple files.

Let''s say I had the following:

#include <stdio.h>

void Heading(void);

int main(void)
{
printf("Hello. I''m about to call my Heading() function\n\n");
Heading();
printf("Now I''m back inside \"main\".\n");
return 0;
}

void Heading(void)
{
printf("Hello! You are currently inside the Heading() ");
printf("function.\n");
}

How would I split this up into seperate files? Would I need a header
file (.h) and a seperate (.c) file in addition to the main (.c) file
that has the main() function in it? Exactly.
What would go where? You would like to put the prototype in a header file (e.g. ''heading.h''),
which you #include in ''main.c'', then put the function declaration in a
separate .c file (e.g. ''heading.c''), then compile and link the two.
Thanks!

fb goes looking for his missing C book...


Good luck! :)

Irrwahn
--
Air is water with holes in it.


这篇关于多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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