Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Topics: Arrays in C. For this assignment, you will write a C program that uses i

ID: 3831595 • Letter: T

Question

Topics: Arrays in C. For this assignment, you will write a C program that uses its first command line parameter to compute and display a histogram of characters that occur in it. Requirements: Your program must compile and run correctly using the gcc compiler on ale You must write the comesponding function definitions for the following function prototypes: set all elements of the histogram to zero void init histogram (int histo IJ)1 construct the histogram from string void cons histogram (char string int histoll) 1 display the histogram to the acreen in a nice format. void display histogram (int histo Your functions must work with the following program: finclude Kotdlib. h> include Katdio.h> define MAX CHAR 255 largest ASCII (Extended) value for characters typedef unsigned char byt may be useful for casting (3) e void init histogram (int histol)) void cons histogram (char string int histo 1 void display histogram (int histoll) 1 int main (int args char 'argv

Explanation / Answer

Please find my implementation of all functions.

Please let me know in case of any issue.

#include <stdio.h>
#include <stdlib.h>

#define MAX_CHARS 255

typedef unsigned char byte;

void init_histogram(int histo[]);
void cons_histogram(char string[], int histo[]);
void display_histogram(int histo[]);

int main(int argc, char const *argv[])
{
  
   return 0;
}

void init_histogram(int histo[]){

   int i;

   for(i=0; i<MAX_CHARS; i++)
       histo[i] = 0;
}

void cons_histogram(char string[], int histo[]){
   int i;
   for(i=0; i<MAX_CHARS; i++){

       int index = (int)string[i];
       histo[index]++; // increasign count
   }
}

void display_histogram(int histo[]){

   int i;
   printf("Char Count ");
   for(int i=0; i<MAX_CHARS; i++){

       char c = (byte)i;
       printf("%c %d ", c, histo[i]);
   }
}