Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topics: Multiple file programs, Makefiles, and Arrays in C. For this assignment, you will write a C program that uses its first command line parameter

Topics: Multiple file programs, Makefiles, and 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 only the lowercase letter[ 'a' 'z' ] 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_LETTERS 26 // number of unique lowercase letter 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 letter 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_LETTERS];

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 h3j5j7k8fjkHS

h appeared 1 time

j appeared 3 times

k appeared 2 times

f appeared 1 time

j 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.

Hints:

Since char values are actually numbers, the following will help you covert back-n-forth between the histo index and the lowercase letter that it represents:

  • 'a' 'a' = 0; 'b' 'a' = 1; 'c' 'a' = 2, , 'z' 'a' = 25
  • 0 + 'a' = 'a'; 1 + 'a' = 'b'; 2 + 'a' = 'c', , 25 + 'a' = 'z'

Please solve the assignment above correctly and as soon as possible.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

LO6 Describe how individual pay rates are set.

Answered: 1 week ago