Skip to content

Instantly share code, notes, and snippets.

@branan
Forked from Lunanne/readfile
Created November 28, 2012 20:11
Show Gist options
  • Save branan/4163910 to your computer and use it in GitHub Desktop.
Save branan/4163910 to your computer and use it in GitHub Desktop.
Hashing code, stupid homework
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