#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 path andwrite the results to a file named as filetowrite.
Input:
path - a pointer to a char string [a character array] specifyingthe path of the directory; and
filetowrite - a pointer to a char string [a character array]specifying the file where results should be written in.
charfreq - a pointer to a long array storing the frequency ofthe 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 the frequency ofthe 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 count thefrequency of each of the above special words. The array
long charfreq[] always has the up-to-date frequencies of specialwords counted so far. If the word is upper case, convert
it to lower case first.
3) Write the result in the output file: filetowrite in followingformat:
character -> frequency
example:
he -> 20
she -> 11
they -> 20
him -> 11
me -> 12
Assumption:
1) You can assume there is no sub-directory under the given pathso you don't have to search the files
recursively.
2) Only .txt files are counted and other types of files shouldbe ignored.
*/
WRITE IN C PLEASE I WILL THUMBS DOWN IF THE ANSWER ISCOPY PASTED