TutoStudio

como-escrever-bons-codigos_exemplo2.2

Dec 20th, 2017
2,966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. [...]
  2. FILE *pArquivo;
  3. int nLinhas = 0;
  4. char caracter;
  5. char palavra[100];
  6.  
  7. if((pArquivo=fopen("meuArquivo.txt", "r")) != NULL){
  8.           while(fscanf(pArquivo, "%c", &caracter) != EOF){
  9.             if(caracter == '\n'){
  10.               nLinhas+=1;
  11.             }
  12.           }
  13.  
  14.           rewind(pArquivo);
  15.             for(i=0; i<rand()%nLinhas+1; i++){
  16.               fscanf(pArquivo, "%s\n", &palavra);
  17.             }
  18. fclose(pArquivo);
  19. [...]
Add Comment
Please, Sign In to add comment