part1
#include<stdio.h>
void report_count();
void accumulate(int k);
int count = 0; /*文件作用域,外部链接*/
int main(void)
{
int value;
register int i;
printf(“enter a positive integer(0 to quit):”);
while(scanf(“%d”,&value) == 1 && value > 0)
{
++count;
for(i = value;i >= 0; i–)
accumulate(i);
printf(“Enter a positive integer (0 to quit):”);
}
report_count();
return 0;
}
void report_count()
{
printf(“Loop executed %d times\n”,count);
}
part2
#include<stdio.h>
extern int count;
static int total = 0;
/*void accumulate(int k)*/
void accumulate(int k)
{
static int subtotal = 0;
if (k <= 0)
{
printf(“loop cycle:%d\n”,count);
printf(“subtotal: %d; total ; %d\n”,subtotal,total);
subtotal = 0;
}
else
{
subtotal = subtotal + k;
total = total + k;
}
我想知道part1 跟part2怎么样链接起来才能运行。
-
近期文章
近期评论
- coolker 发表在《打造最快的Hash表》
- struggle 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- diys 发表在《C语言编程宝典(王大刚) 1.1 C 语言的产生与发展》
文章归档
- 2022 年十月
- 2014 年一月
- 2013 年十二月
- 2012 年十一月
- 2012 年七月
- 2012 年六月
- 2012 年五月
- 2012 年四月
- 2012 年三月
- 2012 年二月
- 2011 年十二月
- 2011 年十月
- 2011 年九月
- 2011 年八月
- 2011 年七月
- 2011 年六月
- 2011 年五月
- 2011 年四月
- 2011 年三月
- 2011 年二月
- 2011 年一月
- 2010 年十二月
- 2010 年十一月
- 2010 年十月
- 2010 年九月
- 2010 年八月
- 2010 年七月
- 2010 年六月
- 2010 年五月
- 2010 年四月
- 2010 年三月
- 2010 年二月
- 2010 年一月
- 2009 年十二月
- 2009 年十一月
- 2009 年十月
- 2009 年九月
- 2009 年八月
- 2009 年七月
- 2009 年六月
- 2009 年五月
- 2009 年四月
- 2009 年三月
- 2009 年二月
- 2009 年一月
- 2008 年十二月
- 2008 年十一月
- 2008 年十月
- 2008 年九月
- 2008 年八月
- 2008 年七月
- 2008 年六月
- 2008 年五月
- 2008 年四月
- 2008 年三月
- 2008 年二月
- 2008 年一月
- 2007 年十二月
- 2007 年十一月
- 2007 年十月
- 2007 年九月
- 2007 年八月
- 2007 年七月
- 2007 年六月
- 2007 年三月
- 2007 年二月
- 2007 年一月
- 2006 年十二月
- 2006 年十一月
- 2006 年十月
- 2006 年九月
- 2006 年八月
- 2006 年七月
- 2006 年六月
- 2006 年五月
- 2006 年四月
- 2006 年三月
- 2006 年二月
- 2006 年一月
- 2005 年十二月
- 2005 年十一月
分类目录
功能
#include<stdio.h>
void report_count();
void accumulate(int k);
extern int count = 0; /*文件作用域,外部链接*/
int main(void)
{
int value;
register int i;
printf(“enter a positive integer(0 to quit):”);
while(scanf(“%d”,&value) == 1 && value > 0)
{
++count;
for(i = value;i >= 0; i–)
accumulate(i);
printf(“Enter a positive integer (0 to quit):”);
}
report_count();
return 0;
}
void report_count()
{
printf(“Loop executed %d times\n”,count);
}
static int total = 0;
/*void accumulate(int k)*/
void accumulate(int k)
{
static int subtotal = 0;
if (k <= 0)
{
printf(“loop cycle:%d\n”,count);
printf(“subtotal: %d; total ; %d\n”,subtotal,total);
subtotal = 0;
}
else
{
subtotal = subtotal + k;
total = total + k;
}
}
C/C++生成程序基本上经历两个大的过程:
一个是编译过程,这个过程把各个源代码文件编译成各自的目标文件(Object File)。
另一个是连接过程,因为上述过程各个目标文件中调用的函数等分散在各自的目标文件中的,需要把他们连接在一起或连接成某种规定格式的可执行文件(程序)。
上述两个文件在用gcc编译的时候命令如下。
gcc -c part1.c part1.o // 参数-c表示只编译不连接,默认有连接操作,这里我们需要编译
gcc -c part2.c part2.o // 同上
gcc part1.o part2.o -o helloworld // 这里表示把part1.o和part2.o连接生成(输出)为helloworld程序。
上述命令需要的其他参数自己查文件,其他编译器操作基本上和这个一样的。