Advertisement
slemos96

Untitled

Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. void main()
  5. {
  6.   FILE *arq;
  7.   char Linha[100];
  8.   char *result;
  9.   int i;
  10.   clrscr();
  11.   // Abre um arquivo TEXTO para LEITURA
  12.   arq = fopen("ArqTeste.txt", "rt");
  13.   if (arq == NULL)  // Se houve erro na abertura
  14.   {
  15.      printf("Problemas na abertura do arquivo\n");
  16.      return;
  17.   }
  18.   i = 1;
  19.   while (!feof(arq))
  20.   {
  21.     // Lê uma linha (inclusive com o '\n')
  22.       result = fgets(Linha, 100, arq);  // o 'fgets' lê até 99 caracteres ou até o '\n'
  23.       if (result)  // Se foi possível ler
  24.       printf("Linha %d : %s",i,Linha);
  25.       i++;
  26.   }
  27.   fclose(arq);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement