#include int main(void) { char *pathFrom, *pathTo; FILE *srcFile, *destFile; char buff[100 + 1]; char *readResult; int writeResult; pathFrom = "C:\\MyFolder\\Homepage\\public_html\\C\\CopyFile\\CopyFileFrom\\CopyFileFrom.txt"; pathTo = "C:\\MyFolder\\Homepage\\public_html\\C\\CopyFile\\CopyFileTo\\CopyFileTo.txt"; /* ファイルを開く */ srcFile = fopen(pathFrom, "r"); if (srcFile == NULL) { /* テキストファイルオープンに失敗した場合 */ printf("can't open '%s'\n", pathFrom); return 1; } destFile = fopen(pathTo, "w"); if (destFile == NULL) { /* テキストファイルオープンに失敗した場合 */ printf("can't open '%s'\n", pathTo); fclose(srcFile); return 1; } /* srcFileから文字列を読み込み、destFileに書き込む */ readResult = fgets(buff, sizeof(buff), srcFile); while (readResult != NULL) { /*printf("%s", buff);*/ writeResult = fputs(buff, destFile); /* 書き込む */ if (writeResult == EOF) { /* 書き込みエラーが発生した場合 */ printf("write error\n"); fclose(srcFile); fclose(destFile); return 1; } readResult = fgets(buff, sizeof(buff), srcFile); } /* ファイルを閉じる */ fclose(srcFile); fclose(destFile); printf("done.\n"); return 0; }