Advertisement
GreMendes

Programa para ver quantidade de linhas de um arquivo txt \o/

Aug 16th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. int contador;
  4. int c;
  5. int main(){
  6.  
  7.     FILE *fp;
  8.    
  9.        
  10.  
  11.     fp = fopen("./vish.txt", "r+");
  12.     if (fp == NULL){
  13.         printf("Ocorreu um erro ao abrir o arquivo!");
  14.         return 1;
  15.     }
  16.  
  17.     do{
  18.  
  19.         contador = fgetc(fp);
  20.         if (contador == '\n'){
  21.             c++;
  22.         }
  23.     } while (contador != EOF);
  24.    
  25.  
  26.     printf("Existem %d linhas", c + 1
  27.         );
  28.  
  29.  
  30.     fclose(fp);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement