diff options
author | Matt Strapp <strap012@umn.edu> | 2020-10-05 09:36:45 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-10-05 09:36:45 -0500 |
commit | 52a693daa19478f3e3c3e7688643cac9d79fdc36 (patch) | |
tree | 05e102a751aa75bc3d1810c76c97a71064a25494 | |
parent | Attempt to work on #5. (diff) | |
download | csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.tar csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.tar.gz csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.tar.bz2 csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.tar.lz csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.tar.xz csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.tar.zst csci4061-52a693daa19478f3e3c3e7688643cac9d79fdc36.zip |
Write a basic version of writeFinalDS
Attempt to start #6
-rw-r--r-- | P1/src/reducer.c | 17 |
1 files changed, 16 insertions, 1 deletions
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[]) { |