各位好,这是C Primer Plus(12.2节内容)上的程序清单。
codeblocks吧
全部回复
仅看楼主
level 7
怎么建工程进行多文件(parta.c 和 partb.c)编译,断断续续差不多搞了两天了,还是有错误,希望大家有时间帮帮忙,看一下,谢谢了。
parta.c文件
----------------------------------------------
#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);
}
partb.c文件
-------------------------------------------------
#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 += k;
total += k;
};
}
2015年09月05日 11点09分 1
level 3
是书上的小错误,印刷的错,
第二个文件中,两个函数这里,上面的这个,后面,要加上一个分号,结尾,话说,楼主,编译器,难道不给你提示错误在哪里????void accumulate(int k)
void accumulate(int k)
2015年09月05日 14点09分 2
嗯,我已经改了那里的错误,但是现在的问题是“怎样将两个文件建立工程来进行编译”,谢谢了。
2015年09月08日 13点09分
1