Skip to content

Instantly share code, notes, and snippets.

@carlosbrando
Created May 9, 2011 00:17
Show Gist options
  • Save carlosbrando/961837 to your computer and use it in GitHub Desktop.
Save carlosbrando/961837 to your computer and use it in GitHub Desktop.
Um programa que lê arquivos e mostra-os na tela
/* DTOS: Um programa que lê arquivos e mostra-os na tela */
#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], "r")) == NULL) {
printf("O arquivo não pode ser aberto.\n");
exit(1);
}
ch = fgetc(fp); /* lê um caractere */
while (ch != EOF) {
putchar(ch); /* imprime na tela */
ch = fgetc(fp);
}
fclose(fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment