The purpose of this program is to introduce you to the manipulation of arrays and cstrings. You must use at least one cstring function to complete this program.
You are to develop a program that will search for a word as well as count the number of words and characters in a text file. Specifically, it will ask the user to input a file name and a word (string) to search. Then it will decide whether the string exists, and count the number of characters (A-Z lower or upper case alphabets, excluding all other symbols or special characters) and words in the file. To simplify the matter, you can consider any character string that is more than 2 characters separated by space, return, or TAB as a word. After that, you report the statistics to the user.
Here are some basic components for your program design.
First, you have a function to get the file name, open the file, and, make sure that the file exits. The function has no input, but should return a file pointer if the file exits. The program asks "Please input the text file name:" Then it reads the input into a cstring, which can be used as a file name to open the file. If the file does not exist, your program notify the user and quit.
Second, if the file exits, your program calls another function that asks for a word "Please input the word to search:". The function will read a string, process the string, and repeat until the end of the file. The input to this function is the file pointer, and the output is a match indicator, number of words, and number of characters.
· This function can read a string from the file into a variable, increase the word count, call another function to count the characters of the string, add the count into the total number of characters, and call another function to compare the string with the "word" to decide whether it is a match. This will go on in a loop until the end of file.
· The function that counts the number of characters should have an input, which is the current string, and an output, which is the count of the number of characters in the string; the function that compares the word with the current string should return yes or no. Presumably it should answer yes even if the word is a substring of the current string.
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.#include<string.h>
void wordSearch(FILE *fp);
FILE* fp = openFile(); //Open the file
wordSearch(fp); //Test the file
FILE* fp; //Declare file pointer
char fileName; //Filename string (set to 20 but can be anything)
printf("Please enter a file name(no more than 20 characters): "); //Prompt user for file name
scanf("%s", fileName); //Read file name
fp = fopen(fileName, "r"); //Open using string for filename in read mode
if(fp == NULL) //If the file does not exist
printf("File does not exist, exiting...\n"); //Tell user and quit
return fp; //Return pointer to file
By purchasing this solution you'll be able to access the following files: