回复 3楼 许大牛
主要代码,没有做任何出错处理。读文in1.txt和in2.txt数学相加输出到out.txt:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
FILE *fin1 = fopen ("in1.txt", "r");
FILE *fin2 = fopen ("in2.txt", "r");
FILE *fout = fopen ("out.txt", "w");
int a, b;
fscanf (fin1, "%d", &a);
fscanf (fin2, "%d", &b);
fprintf (fout, "%d\n", a+b);
exit(0);
}
另一个意思,把两文件的数据内容合并,可以把上面代码改成下面。
代码是:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
FILE *fin1 = fopen ("in1.txt", "r");
FILE *fin2 = fopen ("in2.txt", "r");
FILE *fout = fopen ("out.txt", "w");
int ch;
while ((ch = fgetc(fin1))!= EOF)
{
fputc(ch, fout);
}
while ((ch = fgetc(fin2))!= EOF)
{
fputc(ch, fout);
}
exit(0);
}
详细文件在附件中。只有第一个。
[
本帖最后由 playmyself 于 2010-2-3 23:07 编辑 ]