#include #include "count.h" #include #include void specialcount(char *path, char *fileto
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
#include #include "count.h" #include #include void specialcount(char *path, char *fileto
#include "count.h"
#include <dirent.h>
#include <string.h>
void specialcount(char *path, char *filetowrite, longcharfreq[])
{
/**
The specialcharcount function counts the frequency of thefollowing 5 special words:
"he" "she" "they" "him" "me"
in all the .txt files under directory of the given pathand write the results to a file named as filetowrite.
Input:
path - a pointer to a char string [acharacter array] specifying the path of the directory; and
filetowrite - a pointer to a char string [acharacter array] specifying the file where results should bewritten in.
charfreq - a pointer to a long arraystoring the frequency of the above 5 special words
charfreq[0]: the frequency of "he"
charfreq[1]: the frequency of "she"
charfreq[2]: the frequency of "they"
charfreq[3]: the frequency of "him"
charfreq[4]: the frequency of "me"
Output: a new file named as filetowrite with thefrequency of the above 5 special words written in
Steps recommended to finish the function:
1) Find all the files ending with .txt and store infilelist.
2) Read all files in the filelist one by one and countthe frequency of each of the above special words. The array
long charfreq[] always has the up-to-date frequencies ofspecial words counted so far. If the word is upper case,convert
it to lower case first.
3) Write the result in the output file: filetowrite infollowing format:
character -> frequency
example:
he -> 20
she -> 11
they -> 20
him -> 11
me -> 12
Assumption:
1) You can assume there is no sub-directory under thegiven path so you don't have to search the files
recursively.
2) Only .txt files are counted and other types of filesshould be ignored.
*/
WRITE IN C PLEASE AND PLEASE DONT COPY PASTE OTHERANSWERS