[C / C++] Cでコピーファイル
以下のコードは、入力したファイルの内容をコピーします 1 他のファイルもあなたが入力しました. ソースファイルが表示されない場合は、終了します。. ファイルは同じフォルダでも異なるフォルダでもかまいません。.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include<stdio.h> #include<stdlib.h> int main() { FILE *fp1,*fp2; char ch,f1[1000],f2[1000]; printf ( "Enter source file name(ex:source.txt): " ); scanf ( "%s" ,f1); fp1= fopen (f1, "r" ); if (fp1==NULL) { printf ( "File could not open!!" ); return 0; } printf ( "Enter destination file name(ex:destination.txt): " ); scanf ( "%s" ,f2); fp2= fopen (f2, "w" ); while ((ch= getc (fp1))!=EOF) putc (ch,fp2); printf ( "%s is created and copied" , f2); fclose (fp1); fclose (fp2); return 0; } |
最近のコメント