Program to sort odd and even words from files into separate outputs concurrently.
you have an odd friend who is obsessed with odd words. she calls words that have an odd number of letters and odd word. her definition of “word” is odd as well: a word is a sequence of characters separated by whitespace. as you might suspect she is a programmer.
she feeling a bit overwhelmed and suspects that it is due to a word imbalance. she wants you to write a program that takes in a list of files and reads the words from the file writting the odd words to a file named “odd” and the even words to a file named “even”. the words do not need to be ordered.
for example, if we have three files.
file1.txt:
Hi Sally!
What’s up? Your program does not compiles.
Please fix.
file2.txt:
Sally?
I got the latest update. The program still does not compile.
file3.txt:
Wow Sally!
Nice work. Your code words great. It passes 100% of the tests, and you finished 2 weeks early!
The output files would be:
odd:
I
got
the
update.
The
program
still
not
Wow
work.
up?
program
words
not
compiles.
the
and
you
2
weeks
even:
Sally?
latest
does
compile.
Hi
Sally!
Sally!
Nice
What’s
Your
Your
code
does
great.
It
passes
Please
100%
fix.
of
tests,
finished
early!
you want the program to run fast so, you will create a thread to read each file. the threads must run concurrently. you will also have two threads for writting: one for the even file and one for the odd file. the reader threads must send the words they read to the writer threads using a thread safe blocking queue. the queue must be implemented using pthread mutex and condition variables.
use fscanf(fh, “%ms”, &ptr) to read the words. fscanf will take care of allocating memory for the words. (make sure to free the memory when you are done!)
if there are any errors opening a file, use perror() with the name of the file to print an error to stderr.
Examples
Command to RUN: ./odd_words file1.txt
Command to RUN: ./odd_words file1.txt file2.txt
Command to RUN: ./runvalgrind.sh ./odd_words file1.txt file2.txt file3.txt
Command to RUN: ./odd_words READMES/README.md.1 READMES/README.md.2 READMES/README.md.3 Command to RUN: ./odd_words bigwords
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.