我正在编写一个程序,该程序接受n和n个整数文件,并将该文件组合在一起并在屏幕上输出它,并输出文件“ output.txt”。我为它编写了此代码,但是它既不在屏幕上打印也不在文件上写。
#include <stdio.h>
#include <stdlib.h>
size_t file_size(FILE *f){
fseek(f,0,SEEK_END);
size_t size = ftell(f);
fseek(f,0,SEEK_SET);
return size;
}
void copy(FILE *src, FILE *out){
unsigned char buffer[64];
size_t size = file_size(src);
fseek(src,0,SEEK_SET);
while(fread(buffer,sizeof(buffer),1,src) && size > 0){
if (size < 64){
fwrite(buffer, sizeof(buffer),size,out);
printf("%s",buffer);
size = 0;
}
else{
fwrite(buffer,sizeof(buffer),64,out);
size = size - 64;
printf("%s",buffer);
}
}
printf("\n");
}
int main(){
int num;
char file[100];
scanf("%d",&num);
getchar();
FILE *out;
out = fopen("output.txt","w");
if (out == NULL){
exit(1);
}
for (int i=0;i<num;i++){
scanf("%s",file);
getchar();
FILE *src;
src = fopen(file,"rb");
if (src == NULL){
exit(1);
}
copy(src,out);
fwrite("\n",1,1,out);
fclose(src);
}
fclose(out);
}
您能帮我弄清楚我在做什么错吗。