From c5b67d0cc394c0fb696f724d4da42b77178f9801 Mon Sep 17 00:00:00 2001 From: Andrea Smith Date: Mon, 5 Oct 2020 21:40:15 -0500 Subject: Added (working?) reducer, maybe fixed #6? --- P1/src/reducer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'P1') 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 -- cgit v1.2.3