Em muốn hỏi hàm này khi đọc từ 1 tập tin khác chỉ xuất dc 1 cái ví dụ như xuất ra file khác hay xuất ra màn hình Vậy thì làm sao xuất ra đồng thời cả 2 ạ .
#include<stdio.h>
#include<stdlib.h>
void transFile(FILE* infile, FILE* outfile)
{
int ch;
while (1)
{
ch = fgetc(infile);
if (!feof(infile))
fputc(ch, outfile);
else
break;
}
}
int main()
{
FILE* fpIn;
char* fname = "Data.txt";
fpIn = fopen(fname, "r");
if (fpIn == NULL)
{
printf("File %s not found!\n", fname);
return 0;
}
transFile(fpIn, stdout);
FILE* fpOut;
char* fname2 = "Output.txt";
fpOut = fopen(fname2, "w");
if (fpIn == NULL)
{
printf("File %s not found!\n", fname);
fclose(fpIn);
return 0;
}
transFile(fpIn, fpOut);
fclose(fpOut);
fclose(stdout);
fclose(fpIn);
system("pause");
return 0;
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?