TutoStudio

como-escrever-bons-codigos_exemplo2.1

Dec 20th, 2017
3,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 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.             // Aqui está o problema, pois o ponteiro pArquivo não está mais na posição inicial
  14.             for(i=0; i<rand()%nLinhas+1; i++){
  15.               fscanf(pArquivo, "%s\n", &palavra);
  16.             }
  17. fclose(pArquivo);
  18. [...]
Advertisement
Add Comment
Please, Sign In to add comment