1. (100 pts) Write a program to find the frequency of words in a file. You need to use dynamic memory
allocation for this assignment. Use array of pointers to store the words and frequencies. Set array size
to 1000 and initialize all the pointers to NULL. Structure declaration to store words and frequencies
is as followsstruct wordfreq {
int count;
char *word;
};
When you see a word for the first time, insert into the array with count 1. If the word read from file is
already in the array, increase its count. In this structure, you need to dynamically allocate the space
for each word using malloc().Use argc and argv for input file and output file. Sample execution of the program is given below.
words.txt is the input file which contains one word per line. frequencies.txt is the file to be generated
by your program. It contains frequencies and words, one word and its frequency per line.elk05> assign6 words.txt frequencies.txt
Sample input file is given below
apple
orange
apple
banana
orange
orange
Output file for above input is given below
2 apple
3 orange
1 bananaDon’t forget to deallocate all the space allocated using malloc() and calloc() using free() function.
Run your program under valgrind as shown below to verify that you have no memory leaks.
elk05> valgrind assign6 words.txt frequencies.txt
Somewhere in the output it should say All heap blocks are freed.Submit your program electronically using the blackboard system
The program you submit should be your own work. Cheating will be reported to office of academic integrity.
Both the copier and copiee will be held responsible.
1713, 6, Assignment, Computer, CS, II, Introduction, Programming, to
[SOLVED] Cs 1713 introduction to computer programming ii assignment 6
$25
File Name: Cs_1713_introduction_to_computer_programming_ii_assignment_6.zip
File Size: 565.2 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.