Created
May 9, 2011 02:56
-
-
Save carlosbrando/961973 to your computer and use it in GitHub Desktop.
Copia um arquivo
This file contains hidden or 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
/* 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