Question

4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which should be counted together. The counts have to be stored in array freq in alphabetical order of letters, which corresponds to the increasing order of their ASCII values. Specifically, freq[0] should store the count of and ‘a, freq [1] should store the count of ‘B and ‘b, and so on. This function has also to print the counts indicating each letter and its count on a separate line, as follows: The count of Aand ais. The count of B and b is.. Write a program to test the function. Hint: If variable x of type char represents a lower case letter, then the corresponding index in the array equals the integer value of x-a. If x is an upper case letter, then the index in the array equals x-A.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PLEASE REFER BELOW CODE

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

void letter_freq(const char word[], int freq[])
{
int i;
for(i = 0; word[i] != '\0'; i++) //travelling each alphabet of word
{
if(isupper(word[i])) //if alphabet is uppercase then we are subtracting 65
freq[word[i] - 65]++;
else
freq[word[i] - 97]++; //if it's lowercase we are subtracting 97
}
}
int main()
{
char test_string[20] = "Chegg"; //test string
int freq[26]={0}; //array to count frequency and initialised to 0
int i;
letter_freq(test_string, freq); //calling function

for(i = 0; i < 26; i++) //printing frequency
{
printf("The count of '%c' and '%c' is %d\n",('A' + i), ('a' + i), freq[i]);
}
return 0;
}

PLEASE REFER BELOW OUTPUT

The count of 'A' and 'a' is 0
The count of 'B' and 'b' is 0
The count of 'C' and 'c' is 1
The count of 'D' and 'd' is 0
The count of 'E' and 'e' is 1
The count of 'F' and 'f' is 0
The count of 'G' and 'g' is 2
The count of 'H' and 'h' is 1
The count of 'I' and 'i' is 0
The count of 'J' and 'j' is 0
The count of 'K' and 'k' is 0
The count of 'L' and 'l' is 0
The count of 'M' and 'm' is 0
The count of 'N' and 'n' is 0
The count of 'O' and 'o' is 0
The count of 'P' and 'p' is 0
The count of 'Q' and 'q' is 0
The count of 'R' and 'r' is 0
The count of 'S' and 's' is 0
The count of 'T' and 't' is 0
The count of 'U' and 'u' is 0
The count of 'V' and 'v' is 0
The count of 'W' and 'w' is 0
The count of 'X' and 'x' is 0
The count of 'Y' and 'y' is 0
The count of 'Z' and 'z' is 0

Process returned 0 (0x0) execution time : 0.031 s
Press any key to continue.

Add a comment
Know the answer?
Add Answer to:
4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • u also need to store the letters' ASCII number in the freq array 4. [8] Write...

    u also need to store the letters' ASCII number in the freq array 4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the number of appearances of each letter in the string word and stores them in array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • Write a C++ console application that reverses an array of characters, and counts the number of:...

    Write a C++ console application that reverses an array of characters, and counts the number of:           Lower case characters (islower)           Upper case characters (isupper)           Digits (isdigit)           Other (not one of previous) Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the...

  • Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[],...

    Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[], char destination[], int n); This function copies string source to string destination. Parameter n represents the size of array destination. If the latter array is not sufficiently large to hold the whole source string then only the prefix of the string which has room in the latter array should be copied. Note that after copying, the null character should also be included to mark...

  • The program needs to be written in C. Write a function void camelCase(char* word) where word...

    The program needs to be written in C. Write a function void camelCase(char* word) where word consists of more than two words separated by underscore such as “random_word” or "hello_world_my_name_is_sam". camelCase() should remove underscores from the sentence and rewrite in lower camel case” (https:// en.wikipedia.org/wiki/Camel_case). Watch out for the end of the string, which is denoted by ‘\0’. You have to ensure that legal strings are given to the camelCase() function. The program should only run when the input is...

  • Background: The first step towards helping someone 'decode' a message is often to count how many...

    Background: The first step towards helping someone 'decode' a message is often to count how many times each letter of the alphabet appears in the message. Then divide each count by the total number of letters to compute the relative 'frequency'.   From these frequencies, it may be easier to recognize which letters are assigned to the vowels. For your own reference, here is a table of standard letter frequencies from typical English text. (You do NOT need to display this...

  • Write a program that counts the frequency of each letter of the alphabet as they occur...

    Write a program that counts the frequency of each letter of the alphabet as they occur in a text contained in a text file. The program should read all the characters from a file and tally the frequency for each letter of the alphabet (case-insensitive), along with white space and total character count. Your program's data structure will eventually contain the 26 numbers that will represent the frequencies of occurrence of all 26 letters of the alphabet in that file....

  • C programming (not c++) This programs input is a series of words. All words consist of...

    C programming (not c++) This programs input is a series of words. All words consist of only lowercase letters(a-z), no uppercase letters or digits or punctuation or other special symbols. The program reads until end-of-file, and then prints out the lowercase letters that were not seen in the input. Enter your input: the quick brown fox jumps over the lazy old dog Missing letters: enter your input: roll tide missing letters: a b c f g h j k m...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT