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