aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Smith <smit9523@umn.edu>2020-10-05 21:40:15 -0500
committerAndrea Smith <smit9523@umn.edu>2020-10-05 21:40:15 -0500
commitc5b67d0cc394c0fb696f724d4da42b77178f9801 (patch)
tree7d8125b8a63fac27391ab905c7ab91aa564e256a
parentComments (diff)
downloadcsci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.tar
csci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.tar.gz
csci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.tar.bz2
csci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.tar.lz
csci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.tar.xz
csci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.tar.zst
csci4061-c5b67d0cc394c0fb696f724d4da42b77178f9801.zip
Added (working?) reducer, maybe fixed #6?
-rw-r--r--P1/src/reducer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/P1/src/reducer.c b/P1/src/reducer.c
index cf91e31..ad29f6f 100644
--- a/P1/src/reducer.c
+++ b/P1/src/reducer.c
@@ -48,8 +48,22 @@ void reduce(char *key) {
// Calculate the total count of values (1's) for the word from [the_word].txt
// Store the total count in finalKeyValueDS
// Lather, rinse, repeat for all the words
+ FILE* fptr = fopen(key, "r");
+ char word[BUFFSIZE] = "";
+ fgets(word, BUFFSIZE, fptr); // Buffer is currently entire [the_word].txt file
+
+ char *parsedKey = strtok(word, " "); // Parses input by whitespaces
+ char *parsedWord = parsedKey; // Save the first token, which is the word. It's a surprise tool that will help us later.
+
+ int count = 0;
+ while(parsedKey != NULL) {
+ count++;
+ parsedKey = strtok(NULL, " ");
+ }
+ fclose(fptr);
+ insertNewKeyValue(&DS, parsedWord, count);
}
// write the contents of the final intermediate structure