In c please
Counting the character occurrences in a file
For this task you are asked to write a program that will open a file called “story.txt
and count the number of occurrences of each letter from the alphabet in this file.
At the end your program will output the following report:
Number of occurrences for the alphabets:
a was used-times.
b was used - times.
c was used - times .... ...and so, on
Assume the file contains only lower-case letters and for simplicity just a single
paragraph. Your program should keep a counter associated with each letter of the
alphabet (26 counters) [Hint: Use array|
| Your program should also print a histogram of characters count by adding
a new function print Histogram (int counters []). This function receives the
counters from the previous task and instead of printing the number of times each
character was used, prints a histogram of the counters. An example histogram for
three letters is shown below) [Hint: Use the extended asci character 254]:

Answers

Answer 1

Answer:

#include <stdio.h>

#include <ctype.h>

void printHistogram(int counters[]) {

   int largest = 0;

   int row,i;

   for (i = 0; i < 26; i++) {

       if (counters[i] > largest) {

           largest = counters[i];

       }

   }

   for (row = largest; row > 0; row--) {

       for (i = 0; i < 26; i++) {

           if (counters[i] >= row) {

               putchar(254);

           }

           else {

               putchar(32);

           }

           putchar(32);

       }

       putchar('\n');

   }

   for (i = 0; i < 26; i++) {

       putchar('a' + i);

       putchar(32);

   }

}

int main() {

   int counters[26] = { 0 };

   int i;

   char c;

   FILE* f;

   fopen_s(&f, "story.txt", "r");

   while (!feof(f)) {

       c = tolower(fgetc(f));

       if (c >= 'a' && c <= 'z') {

           counters[c-'a']++;

       }

   }

   for (i = 0; i < 26; i++) {

       printf("%c was used %d times.\n", 'a'+i, counters[i]);

   }

   printf("\nHere is a histogram:\n");

   printHistogram(counters);

}

In C Please Counting The Character Occurrences In A FileFor This Task You Are Asked To Write A Program
In C Please Counting The Character Occurrences In A FileFor This Task You Are Asked To Write A Program
In C Please Counting The Character Occurrences In A FileFor This Task You Are Asked To Write A Program
In C Please Counting The Character Occurrences In A FileFor This Task You Are Asked To Write A Program

Related Questions

Why is it important to isolate evidence-containing devices from the internet?
To save the battery
To hide their location
Devices can be remotely locked or wiped if connected
It is not important to isolate the devices

Answers

Answer:

C.

Devices can be remotely locked or wiped if connected

Explanation:

Other Questions
What number is 0.01 more than 253.498? The fossil presence of anatomically modern humans in ________ demonstrates that our ancestors were capable of substantial water crossings by 40,000 years ago. Trisha packs x boxes with 12 bottles in each box. The total number of bottles she packs is 216. Which equation and solution represent the total number of boxes Trisha packs?help asap ty :) A is an organism that eats other organisms to gain energy; it is also called . Which security measure provides protection from IP spoofing? A ______ provides protection from IP spoofing.PLEASE HELP I need to finish 2 assignments to pass this school year pleasee im giving my only 30 points please !!!!!!Please help ASAP!!!!!AB and BC form a right angle at their point of intersection, B. If the coordinates of A and Bare (14, -1) and (2, 1), respectively, the y-intercept of AB is 4/3 and the equation of BC is y= 6 X + If the y-coordinate of point Cis 13, its x-coordinate is 1. Zerbie sees a psychologist who tells them that the past is not what's important - it's all abouttheir future! Zerbie's psychologists listens carefully to what they say, repeating the informationback and asking for clarification. Zerbie is in charge of deciding what the problem is and how togrow and meet their needs. What type of psychologist is Zerbie seeing?a. Psychoanalystb. BehavioristC. Biopsychologistd. Humanist 2h + 10 = 20 solve the value for h the___ air in the small cabin forced us outside Viruses vary in size and structure, but what is one thing they have in common?a. they destroy the host cellb. they all cause terminal illnessc. they all hijack a host celld. none of the above Please helpp Extra points and brainleist The angle of depression of a point G on a horizontal ground from top T of an electrical pole is 25. If the distance from G to the foot of the pole is 45m, calculate the height of the pole to the nearest whole number. PS: use scale 1:9. Which of the following was a successful effort by Congress to protect the rights of the newly freed enslaved people?A. the Homestead ActB. the Wade-Davis BillC. the Freedmens BureauD. the Land Morrill Grant ActE. the Ten Percent Plan Which of the following BEST exemplifies the difference between the adult justice process and the juvenile justice process?A Juveniles must go before a judge and adults do not.B. Adults have the right to an attorney and juveniles do not.C. Juveniles have the right to an appeal and adults do not.D. Adults have the right of trial by jury and juveniles do not. The length of one side of a square is 3m^4. What is the area of the square? (A = I x w)a. 3m^4b. 6m^8C. 9m^8d. 6m^6 Identify the characteristics of syntax errors. Choose all that apply.programmer did not follow the program language conventionsmay be highlighted while writing the programcan be caused by mistyping or misspelling while writing the programdoes not cause an error message Explain the advantages to a plant of having its cell membranes surrounded by cell walls A model rocket is launched with an initial upward velocity of 188 ft/s. The rocket's height h (in feet) after t seconds is given by the following.h=188t-16t^2Find all values of for which the rocket's height is 92 feet.Round your answer(s) to the nearest hundredth.(If there is more than one answer, use the "or" button.) i need a paragraph of the movie "The Giver". can someone please help me. HURRY SPONISH______ descansa ella? A las dos de la tarde?_______ descansan ellos? En el parque?________ visita el museo? Marco?_______ compramos ropa en Amazon? Porque es fcil?_______ lleva usted a la fiesta? Los jeans?________ vamos al centro comercial? En taxi?__________ vais vosotros? Al cine?__________ vas al cine? Con Maria?_________ clases tienes? Siete? ________es tu clase favorita? Espaol o Matemticas?