Created
April 27, 2013 00:21
-
-
Save johno/5471330 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* | |
* | |
* Created on: Feb 1, 2012 | |
* Author: johnotander | |
*/ | |
#include "TheTokens.h" | |
//The constants. | |
const int BUFFERSIZE = 1000; | |
//Prints the table for word length frequencies. | |
void printwf(HashTablePtr table) | |
{ | |
int i; | |
for(i = 0; i < table->size-1; i++) | |
{ | |
if(((ListPtr)(table->buckets[i]))->size != 0) | |
printf("%s : %d\n", ((HashObjectPtr)((NodePtr)((ListPtr)(table->buckets[i]))->head)->data)->key, ((ListPtr)(table->buckets[i]))->size); | |
} | |
} | |
//This method receives the line and processes it. | |
HashTablePtr processInput(HashTablePtr table) | |
{ | |
//The local variables. | |
char *buffer = malloc(BUFFERSIZE * sizeof(char)); | |
char *delims = malloc(BUFFERSIZE * sizeof(char)); | |
char *tokens; | |
//The delimiters. | |
strcpy(delims, ",.;:'\"&/()<>%|#@~{}[]!*? -_\n\t"); | |
//Reads line by line until we reach EOF. | |
while(fgets(buffer, BUFFERSIZE, stdin) != NULL) | |
{ | |
//Tokenizes words in string. | |
tokens = strtok(buffer, delims); | |
//Runs through all tokens in the array. | |
while(tokens != NULL) | |
{ | |
table = insert(table, newHashObject(tokens, NULL)); | |
tokens = strtok(NULL, delims); | |
} | |
} | |
//Release the arrays. | |
free(buffer); | |
free(delims); | |
return table; | |
} |
This file contains 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
/* | |
* TheTokens.h | |
* | |
* Created on: Apr 21, 2012 | |
* Author: johnotander | |
*/ | |
#ifndef THETOKENS_H_ | |
#define THETOKENS_H_ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include "HashTable.h" | |
#include "HashObject.h" | |
void printLine(); | |
void printwf(HashTablePtr table); | |
HashTablePtr processInput(HashTablePtr table); | |
#endif /* THETOKENS_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment