Skip to content

Instantly share code, notes, and snippets.

@carlosbrando
Created May 9, 2011 00:13
Show Gist options
  • Save carlosbrando/961834 to your computer and use it in GitHub Desktop.
Save carlosbrando/961834 to your computer and use it in GitHub Desktop.
Gravando do teclado para o disco.
/* KTDO: Do teclado para o disco. */
#include <stdio.h>
#include <stdlib.h>
main(int argc, char const *argv[]) {
FILE *fp;
char ch;
if (argc != 2) {
printf("Você esqueceu de digitar o nome do arquivo.\n");
exit(1);
}
if ((fp = fopen(argv[1], "w")) == NULL) {
printf("O arquivo não pode ser aberto.\n");
exit(1);
}
do {
ch = getchar();
putc(ch, fp);
} while(ch != '$');
fclose(fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment