Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. void PreencheTabelaPalavras ( char *ficheiro, st_texto *t )
  2. {
  3. FILE *f;
  4. int n,l;
  5. char *palavra;
  6.  
  7. f = AbreFicheiro ( ficheiro, "r" );
  8. while ( ( palavra = LePalavra ( f ) ) != NULL ) {
  9. if ( ( n = NovaPalavra ( palavra, &(*t) ) ) == -1 ) {
  10. l=strlen(palavra);
  11. (*t).palavras[(*t).n_dist_palavras] = (char *)malloc(sizeof(char) * (l+1)) /* -- Insert code for memory allocation --*/;
  12. if ( (*t).palavras[(*t).n_dist_palavras] == NULL ) {
  13. fprintf ( stderr, "ERROR: not enough memory available!\n" );
  14. exit ( 3 );
  15. }
  16.  
  17. strcpy ( (*t).palavras[(*t).n_dist_palavras], palavra );
  18. (*t).ocorrencias[(*t).n_dist_palavras]++;
  19. (*t).n_dist_palavras++;
  20. }
  21. else {
  22. (*t).ocorrencias[n]++;
  23. }
  24. }
  25. fclose ( f );
  26. return;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement