Question
GIVEN CODE: file_stats.c #include #include libfs.h int main () { int num_space, num_char, num_period, num_word; float avg_wl; const char * filename = text.txt; num_char =
GIVEN CODE:
file_stats.c
#include
int main () { int num_space, num_char, num_period, num_word; float avg_wl; const char * filename = "text.txt";
num_char = find_char(filename, '*'); num_space = find_char(filename, ' '); num_word = num_space + 1; num_period = find_char(filename, '.');
avg_wl = (num_char - num_space - num_period)/(float)num_word;
printf("Number of characters: %d ", num_char); printf("Number of words: %d ", num_word); printf("Average word length: %.1f ", avg_wl); return 0; }
GIVEN TEXT (text.txt)
We are counting the words in this file. We also count all the characters. Then we calculate the average word length...
MAIN QUESTION (C PROGRAM)
Write a function that opens a file named text.txt and counts for a character within that file. If the character being searched for is ? , then return the number of all the characters in the file. The calculation of the word count, character count, and average word length is done in file stats.c (which is given to you). Your job is to create a libfs.c and libfs.h. The following function prototype must be used: int find char(const char * filename, char thisc); A sample input file text.txt is provided to test your code.
The expected output for the sample file is:
Number of characters: 118
Number of words: 21
Average word length: 4.4
Hints to understand how the provided file stats.c code works: Hello world. has 12 characters, 2 words, and 1 period, and an average word length of 5 (measured in characters), but how did you know there were two words? Helloworld. is 1 word, 11 characters, has 1 period, and has an average word length of 10. What separates words? Can we count the separations instead of the actual words? Can we calculate the average word length by summing all the characters only associated with words? Read the file stats.c code carefully to find the logic, then write the function int find_ char to complete the code. Note: In file_stats.c we assume there are no double spaces in the input file and the file does not end in a space. The total number of characters includes spaces and punctuation. We also assume there are no linefeeds ( ), and there are only periods for punctuation. The average word length does not include punctuation as part of a word.
Must compile two separate files, one header and one main as mentioned above. Will like to see the output when you run it thank you
(libfs.c and libfs.h. )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started