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

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 corresponding function definitions for the following function prototypes:

// set all elements of the histogram to zero

void init_histogram(int histo[]);

// construct the histogram from string

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

// display the histogram to the screen in a nice format

void display_histogram(int histo[]);

Your functions must work with the following program:

#include

#include

#define MAX_CHAR 255 // largest ASCII(Extended) value for characters

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

void init_histogram(int histo[]);

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

void display_histogram(int histo[]);

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

{

int histo[256];

if (args == 2)

{

init_histogram(histo);

cons_histogram(argv[1], histo);

display_histogram(histo);

}

else

exit(1);

return 0;

}

void init_histogram(int histo[])

{

// your code here

}

void cons_histogram(char string[], int histo[])

{

// your code here

}

void display_histogram(int histo[])

{

// your code here

}

Outline:

Create / open a .c file using pico, in your UNIX account

Write the necessary C statementss to meet the game specification given above

Make sure to test your program when it is done

You really need to run your program a number of time to do this thoroughly

Notes(s):

Only those characters that occurred at least once are reported.

The minimal 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 as unsigned to be safe.

Sample Run(s):

% ./a.out hgfjkddjkrui3

3 appeared 1 time

d appeared 2 times

f appeared 1 time

g appeared 1 time

h appeared 1 time

i appeared 1 time

j appeared 2 times

k appeared 2 times

r appeared 1 time

u appeared 1 time

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!