我有下面的代碼,我想寫逆向一個文件的內容複製到另一個文件複製逆向一個文件的內容複製到另一個文件
# include <stdio.h>
# include <conio.h>
# include <process.h>
void main()
{
FILE *f1,*f2;
char file1[20],file2[20];
char ch;
int n;
printf("Enter the file1 name:");
scanf("%s",file1);
printf("Enter the file2 name:");
scanf("%s",file2);
f1=fopen(file1,"r");
f2=fopen(file2,"w");
if(f1==NULL || f2==NULL)
{
printf("Cannot open file");
exit(1);
}
printf("Characters to read from end of file :");
scanf("%d",&n);
fseek(f1,-n,SEEK_SET);
while(!feof(f1))
{
ch=fgetc(f1);
fputc(ch,f2);
}
fcloseall();
getche();
但執行後,內容不會被反寫訂單,但它被複制,因爲它是,我已經使用
fseek(f1,-n,SEEK_SET).
我不知道我哪裏錯了。
謝謝小提琴比特:) – user3027039
@ user3027039任何時候。 –