Created
September 28, 2014 07:14
-
-
Save ungikim/4a5598102851cb663f45 to your computer and use it in GitHub Desktop.
한빛미디어 유닉스시스템프로그래밍 연습문제 2장 4번
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define BUF_SZB 512 | |
void error(const char *s) { | |
printf("%s\n", s); | |
exit(EXIT_FAILURE); | |
} | |
int main(int argc, char** argv) { | |
FILE* from_fp; | |
FILE* to_fp; | |
char buf[BUF_SZB]; | |
if (3 != argc) { | |
error("Usage: ./oddcat from-file to-file"); | |
} | |
if (NULL == (from_fp = fopen(argv[1], "r"))) { | |
error("Could't open from-file for reading"); | |
} | |
if (NULL == (to_fp = fopen(argv[2], "w+"))) { | |
error("Could't create to-file for writng"); | |
} | |
while(0 < fread(buf, sizeof(char), 2, from_fp)) { | |
fwrite(buf, sizeof(char), 1, to_fp); | |
} | |
if (-1 == fclose(from_fp)) { | |
error("Could't close from-file"); | |
} | |
if (-1 == fclose(to_fp)) { | |
error("Could't close to-file"); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment