From 52a693daa19478f3e3c3e7688643cac9d79fdc36 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 5 Oct 2020 09:36:45 -0500 Subject: Write a basic version of writeFinalDS Attempt to start #6 --- P1/src/reducer.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'P1') diff --git a/P1/src/reducer.c b/P1/src/reducer.c index 7afb9ee..4d501dd 100644 --- a/P1/src/reducer.c +++ b/P1/src/reducer.c @@ -1,5 +1,7 @@ #include "reducer.h" +fianlKeyValueDS DS; + // create a key value node finalKeyValueDS *createFinalKeyValueNode(char *word, int count){ finalKeyValueDS *newNode = (finalKeyValueDS *)malloc (sizeof(finalKeyValueDS)); @@ -49,7 +51,20 @@ void reduce(char *key) { // write the contents of the final intermediate structure // to output/ReduceOut/Reduce_reducerID.txt void writeFinalDS(int reducerID){ - + + finalKeyValueDS *root = &DS; + finalKeyValueDS *tempNode = root; + + while(tempNode != NULL) { + // Shove word and ones in a file named word.txt + char filename[150]; + sprintf(filename, "output/MapOut/Map_%d/%s.txt", reducerID, tempNode -> key); + FILE* fptr = fopen(filename, "w"); + fprintf(fptr, "%s %d", tempNode -> key, tempNode -> value); + fclose(fptr); + tempNode = tempNode -> next; + } + freeFinalDS(root); } int main(int argc, char *argv[]) { -- cgit v1.2.3