Created
July 26, 2017 12:59
-
-
Save hamadu/478d22e52c1bee2e2c3a454fe6738027 to your computer and use it in GitHub Desktop.
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 <sys/types.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
void print_error_and_exit() { | |
printf("error(%d): %s\n", errno, strerror(errno)); | |
exit(1); | |
} | |
int main(int argc, char* argv[]) { | |
FILE *src = fopen("./src.txt", "r"); | |
if (src == NULL) { | |
print_error_and_exit(); | |
} | |
FILE *dst = fopen("./dst.txt", "w"); | |
if (dst == NULL) { | |
print_error_and_exit(); | |
} | |
while (1) { | |
int ch = fgetc(src); | |
if (ch == EOF) { | |
break; | |
} | |
fputc(ch, dst); | |
} | |
fclose(src); | |
fclose(dst); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment