#include #include #include #include "hash.h" TABLE_EL *table = NULL; void read_file( char *s ) { FILE *fp; char tmp[80]; TABLE_EL *ptr; TABLE_EL new_el; fp = fopen( s, "r" ); if( fp == NULL ) { printf( "Impossibile aprire %s\n", s ); exit( 1 ); } while( fscanf( fp, "%s", tmp ) != EOF ) { ptr = search( table, tmp ); if( ptr == NULL ) { printf( "==> %s\n", tmp ); new_el.word = tmp; new_el.freq = 1; insert( table, &new_el ); } else { printf( "Aggiorno %s\n", tmp ); ptr->freq++; } } fclose( fp ); } void print_freq( void ) { TABLE_EL *ptr; int i; for( i = 0; i < HASH_TABLE_SIZE; i++ ) { ptr = &(table[i]); if( ptr->word != NULL ) printf( "%20s %5d\n", ptr->word, ptr->freq ); } } int main( int argc, char **argv ) { if( argc < 2 ) { printf( "Uso: frequenze nomefile\n" ); exit( 1 ); } create( &table ); read_file( argv[1] ); print_freq(); dispose( &table ); return( 0 ); }