반응형
copy file
1. 소스
#include <stdio.h> #include <stdlib.h> int main() { char ch; char source_file[20] = "source.txt"; char target_file[20] = "target.txt"; FILE *source, *target; source = fopen(source_file, "r"); if( source == NULL ) { exit(EXIT_FAILURE); } target = fopen(target_file, "w"); if( target == NULL ) { fclose(source); exit(EXIT_FAILURE); } while( ( ch = fgetc(source) ) != EOF ) fputc(ch, target); printf("File copied successfully.\n"); fclose(source); fclose(target); return 0; }
2. 결과
gcc -o copy_file copy_file.c hacker@HACKER:~/c$ ./copy_file File copied successfully.
반응형
'C 언어' 카테고리의 다른 글
공유(shared) 라이브러리 만들기 (0) | 2016.07.19 |
---|---|
정적 라이브러리 만들기 (0) | 2016.07.19 |
binary search (0) | 2016.07.12 |
search (0) | 2016.07.12 |
insertion sort (0) | 2016.07.12 |