Skip to content

Instantly share code, notes, and snippets.

@carlosbrando
Created May 9, 2011 02:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosbrando/961973 to your computer and use it in GitHub Desktop.
Save carlosbrando/961973 to your computer and use it in GitHub Desktop.
Copia um arquivo
/* Copia um arquivo */
#include <stdio.h>
#include <stdlib.h>
main(int argc, char const *argv[]) {
FILE *in, *out;
char ch;
if (argc != 3) {
printf("Você esqueceu de digitar o nome do arquivo.\n");
exit(1);
}
if ((in = fopen(argv[1], "rb")) == NULL) {
printf("O arquivo-fonte não pode ser aberto.\n");
exit(1);
}
if ((out = fopen(argv[2], "wb")) == NULL) {
printf("O arquivo-destino não pode ser aberto.\n");
exit(1);
}
/* Esse código copia de fato o arquivo */
while (!feof(in)) {
ch = getc(in);
if (!feof(in)) putc(ch, out);
}
fclose(in);
fclose(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment