Skip to content

Instantly share code, notes, and snippets.

@hamadu
Created July 26, 2017 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamadu/478d22e52c1bee2e2c3a454fe6738027 to your computer and use it in GitHub Desktop.
Save hamadu/478d22e52c1bee2e2c3a454fe6738027 to your computer and use it in GitHub Desktop.
#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