#include #include #define SIZE 256 int main(void) { char fname[SIZE], tname[SIZE]; int c; FILE *from, *to; printf("コピー元のファイル名を入力してください:"); scanf("%s", fname); printf("コピー先のファイル名を入力してください:"); scanf("%s", tname); if ( (from = fopen(fname, "r")) == NULL) { printf("[エラー] %s を開けませんでした\n", fname); return 1; } if ((to = fopen(tname, "w")) == NULL) { printf("[エラー] %s を開けませんでした\n", tname); return 1; } c = fgetc(from); while (c != EOF) { fputc(c, to); c = fgetc(from); } fclose(from); fclose(to); printf("%s に %s の内容をコピーしました\n", tname, fname); return 0; }