Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // exercicio de ED
- // Abertura e leitura do n0 de linhas de um arquivo
- #include <stdio.h>
- #include <stdlib.h>
- #ifdef WIN32
- #include <conio.h>
- #define LIMPA_TELA system("cls")
- #else
- #include <ncurses.h>
- #define LIMPA_TELA system("clear")
- #endif
- int main()
- {
- int nl=0;
- char c;
- FILE *arq;
- arq=fopen("entrada.txt", "rt"); //abre o arquivo
- if (arq==NULL)
- {
- printf("Não foi possível abrir o arquivo.\n");
- exit(1);
- }
- while(fscanf(arq,"%c",&c)==1)
- {
- if(c=='\n') nl++;
- }
- fclose(arq);//fecha o arquivo
- printf("Numero de linhas = %d\n", nl); /* exibe o resultado na tela */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement