c语言 英文单词频率统计 哈希存储
从一段英文文章中找到频率最大的几个单词,同时统计不同单词个数以及总单词个数,利用哈希进行存储。
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define HASH_TABLE_SIZE 49999
typedef struct word{
char wrd[80];
int num;
}word;
static int diff_words=0;
static int total_words=0;
word *hashtable[HASH_TABLE_SIZE];
int hash(int number){
return number%HASH_TABLE_SIZE;
}
void insert(int count,char *w)
{
int pos=hash(count);
word *newWord;
total_words++;
while (hashtable[pos])
{
if(!strcmp(hashtable[pos]->wrd,w))
{
hashtable[pos]->num++;
return;
}
else
{
pos++;
}
}
newWord=(word*)malloc(sizeof(word));
newWord->num=1;
strcpy(newWord->wrd,w);
hashtable[pos]=newWord;
diff_words++;
}
int main()
{
FILE *fp;
char wrd_temp[80],ch;
word *head,*curr;
int i,