Write a program that reads a text file selected by the user and prints a report
ID: 3651451 • Letter: W
Question
Write a program that reads a text file selected by the user and prints a report on the screen indicating how many lines of text were read, how many words were read, how many total characters were read, how many vowels were read, how many consonants were read, and how many whitespace characters were read. The user must be able to enter the name of the file. Allow the user to reenter the filename whenever the file specified cannot be opened. Assume that vowels are the uppercase or lowercase letters a, e, i, o, and u. For the purposes of this program a word is a sequence of one or more letters or digits followed by any other character than a letter or digit. For example, here is the output produced by a program that satisfies the requirements of this assignment when run on the file namedExplanation / Answer
# include # include # include int static words = 0,chars = 0,senten = 0; int i = 0; main()/*start of main function*/ { char ch; char ch1[1000]; FILE*fp; FILE*fp1; fp1 = fopen("NUMBERofCHars.txt","w"); fp = fopen("Paragraph.txt","r+"); while((ch=fgetc(fp)) != EOF) { ch1[i] = ch; if (ch1[i] == '.'){/*condition for number of sentences*/ senten = senten + 1; } if (ch1[i] != ' '){/*Condition for number of letters*/ chars = chars + 1; } if (ch1[i] == ' '){/*condition for number of words*/ words = words + 1; } i++; } fprintf(fp1,"Number of words : %d ",words); fprintf(fp1,"Number of letters: %d ",chars); fprintf(fp1,"Number of sentence: %d ",senten); fclose(fp); fclose(fp1); }/*End of main*/Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.