Question: For this assignment, you will write a C program that uses its first command line parameter to compute and display a histogram of only the

For this assignment, you will write a C program that uses its first command line parameter to compute and display a histogram of only the digit [ '0' '9' ] characters that occur in it.

Requirements:

Your program must compile and run correctly using the gcc compiler on ale.

You must write the corresponding histo.c file for the following histo.h file:

#define NUM_DIGITS 10 // number of unique digit characters

typedef unsigned char byte; // may be useful for casting(s)

void init_histogram(int histo[]); // set all elements of the histogram to zero

void cons_histogram(const char string[], int histo[]); // construct the histogram from string

void most_frequent(const int histo[], char* ret_val); // set *ret_val to a most occurring digit character hence returning it

void display_histogram(int* const histo); // display the histogram sparsely

Your histo.c file must also work with the following main.c file:

#include

#include

#include "histo.h"

int main(int args, char *argv[])

{

int histo[NUM_DIGITS];

if (args == 2)

{

init_histogram(histo);

cons_histogram(argv[1], histo);

display_histogram(histo);

}

else

exit(1);

return 0;

}

You must write an appropriate Makefile

Once complete and working, your program must produce output very similar to:

Sample Runs:

% ./main h3j5j7k8fjksk8

3 appeared 1 time

5 appeared 1 time

7 appeared 1 time

8 appeared 2 times

8 occurred most often

Notes:

Only those characters that occurred at least once are reported, and only those that occurred more than one are reported as plural.

The maximal occurrence may very well not be unique.

The value of a char variable is an integer value and hence can be used as an index into the histogram once casted to a byte to be safe.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!