-
-
Save branan/4163910 to your computer and use it in GitHub Desktop.
Hashing code, stupid homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE * fp = fopen("woorden.txt","rb"); | |
char tempBuffer[35]; | |
while(fgets(tempBuffer,sizeof(tempBuffer),fp)!=NULL) | |
{ | |
//we found a word.Let's assume its shorter than 35 characters and we can safe some space | |
int length = strlen(tempBuffer); | |
word = malloc(length*sizeof(char)); | |
strncpy(word,tempBuffer,length); | |
if(word[length-1]=='\n') | |
word[length-1] = '\0'; | |
else | |
word[length]='\0'; | |
//put it in the hashlist | |
unsigned int hashcode = hashCode(word); | |
int index = hashcode%HASHARRAYSIZE; | |
ELEMENT* newNode = malloc(sizeof(ELEMENT)); | |
newNode->next = hashArray[index]; | |
newNode->word = word; | |
hashArray[index] = newNode; | |
} | |
fclose(fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment