Program to sort odd and even words from files into separate outputs concurrently.
Need help with this assignment?Get an original answer from a qualified tutor — from $10/page.
Get it written →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
Get a plagiarism-free answer to this question
Send us your instructions and we’ll match you with the best writer in your subject.
- 100% human-written, zero AI
- Turnitin report included
- Confidential — we never share your data
- Free revisions & refunds