From 0306093118d171bb332bd8b8d4cf9d66a6ff1d84 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 2 Nov 2020 18:40:44 -0600 Subject: Pain --- P2/lib/utils.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/P2/lib/utils.c b/P2/lib/utils.c index b9454bb..577ca64 100644 --- a/P2/lib/utils.c +++ b/P2/lib/utils.c @@ -38,7 +38,6 @@ void sendChunkData(char *inputFile, int nMappers) { int fd = open(inputFile, O_RDONLY); // construct chunks of 1024 bytes while(read(fd, message.msgText, chunkSize) != 0) { - // printf("%s\n", message.msgText); /* Go to the end of the chunk, check if final character is a space if character is a space, do nothing else cut off before that word and put back file. @@ -46,16 +45,18 @@ void sendChunkData(char *inputFile, int nMappers) { Maybe copy message.msgText into a new array, do the backwards iteration, and then replace message.msgText with the temp array? Or something? */ - //fseek()?? - //https://www.tutorialspoint.com/c_standard_library/c_function_fseek.htm + //lseek()?? (LOW LEVEL) + //http://crasseux.com/books/ctutorial/Finding-file-positions-at-a-low-level.html // TODO! help - // int i = 1023; - // while(message.msgText[i] != ' ') { - // message.msgText - // } - + int i = 1023; + while(message.msgText[i] != ' ') { + i--; + printf("%d\n", i); + } + lseek(fd, (i - 1023), SEEK_CUR); + printf("%s\n", message.msgText); message.msgType = (map++ % nMappers) + 1 ; //THIS IS DEBUG, NOT ACTUALLY FUNCTIONAL (like at all) msgsnd(msgid, &message, map, 0); -- cgit v1.2.3 From 6df4c98a968564f90b4919af7bea607a7381a392 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 2 Nov 2020 18:43:30 -0600 Subject: Help please --- P2/lib/utils.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/P2/lib/utils.c b/P2/lib/utils.c index 577ca64..8abac72 100644 --- a/P2/lib/utils.c +++ b/P2/lib/utils.c @@ -50,12 +50,13 @@ void sendChunkData(char *inputFile, int nMappers) { // TODO! help - int i = 1023; - while(message.msgText[i] != ' ') { - i--; - printf("%d\n", i); - } - lseek(fd, (i - 1023), SEEK_CUR); + // int i = 1023; + // while(message.msgText[i] != ' ') { + // i--; + // message.msgText[i] == '\0'; + // printf("%d\n", i); + // } + // lseek(fd, (i - 1023), SEEK_CUR); printf("%s\n", message.msgText); message.msgType = (map++ % nMappers) + 1 ; //THIS IS DEBUG, NOT ACTUALLY FUNCTIONAL (like at all) -- cgit v1.2.3 From 4ca3e0cc18945ad20061ae02651f1c407d736f15 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 2 Nov 2020 18:54:06 -0600 Subject: please help --- P2/lib/utils.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/P2/lib/utils.c b/P2/lib/utils.c index 8abac72..ac35243 100644 --- a/P2/lib/utils.c +++ b/P2/lib/utils.c @@ -35,9 +35,9 @@ void sendChunkData(char *inputFile, int nMappers) { // open message queue int msgid = openQueue("map"); int map = 1; - int fd = open(inputFile, O_RDONLY); + FILE* file = fopen(inputFile, "r"); // construct chunks of 1024 bytes - while(read(fd, message.msgText, chunkSize) != 0) { + while(fgets(message.msgText, chunkSize + 1, file) != NULL) { /* Go to the end of the chunk, check if final character is a space if character is a space, do nothing else cut off before that word and put back file. @@ -45,18 +45,14 @@ void sendChunkData(char *inputFile, int nMappers) { Maybe copy message.msgText into a new array, do the backwards iteration, and then replace message.msgText with the temp array? Or something? */ - //lseek()?? (LOW LEVEL) - //http://crasseux.com/books/ctutorial/Finding-file-positions-at-a-low-level.html - // TODO! help - - // int i = 1023; - // while(message.msgText[i] != ' ') { - // i--; - // message.msgText[i] == '\0'; - // printf("%d\n", i); - // } - // lseek(fd, (i - 1023), SEEK_CUR); + int i = 1023; + while(message.msgText[i] != ' ' || message.msgText[i] != '.') { + i--; + message.msgText[i] == '\0'; + printf("%d\n", i); + } + fseek(file, (i - 1023), SEEK_CUR); printf("%s\n", message.msgText); message.msgType = (map++ % nMappers) + 1 ; //THIS IS DEBUG, NOT ACTUALLY FUNCTIONAL (like at all) @@ -67,7 +63,7 @@ void sendChunkData(char *inputFile, int nMappers) { struct msgBuffer END = {i, "END"}; msgsnd(msgid, &END, MSGSIZE, 0); } - + fclose(file); } // hash function to divide the list of word.txt files across reducers -- cgit v1.2.3