Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 658313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:55:11+00:00 2026-05-13T22:55:11+00:00

I am having trouble with a homework question that I’ve been working at for

  • 0

I am having trouble with a homework question that I’ve been working at for quite some time.
I don’t know exactly why the question is asking and need some clarification on that and also a push in the right direction.

Here is the question:

(2) Solve this problem using one single subscripted array of counters. The program uses an array of characters defined using the C initialization feature. The program counts the number of each of the alphabetic characters a to z (only lower case characters are counted) and prints a report (in a neat table) of the number of occurrences of each lower case character found. Only print the counts for the letters that occur at least once. That is do not print a count if it is zero. DO NOT use a switch statement in your solution. NOTE: if x is of type char, x-‘a’ is the difference between the ASCII codes for the character in x and the character ‘a’. For example if x holds the character ‘c’ then x-‘a’ has the value 2, while if x holds the character ‘d’, then x-‘a’ has the value 3. Provide test results using the following string:

“This is an example of text for exercise (2).”

And here is my source code so far:

#include<stdio.h>

int main() {

    char c[] = "This is an example of text for exercise (2).";
    char d[26];
    
    int i;
    int j = 0;
    int k;
    
    j = 0;

    //char s = 97;

    for(i = 0; i < sizeof(c); i++) {
        for(s = 'a'; s < 'z'; s++){
            if( c[i] == s){
                
                k++;
                printf("%c,%d\n", s, k);
                k = 0;

            }
        }
    }
    return 0;
    
}

As you can see, my current solution is a little anemic.
Thanks for the help, and I know everyone on the net doesn’t necessarily like helping with other people’s homework. ;P

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:55:11+00:00Added an answer on May 13, 2026 at 10:55 pm
    char c[] = "This is an example of text for exercise (2).";
    int d[26] = {0}, i, value;
    
    for(i=0; i < sizeof(c) - 1; i++){ //-1 to exclude terminating NULL
       value = c[i]-'a';
       if(value < 26 && value >= 0) d[value]++;
    }
    
    for(i=0; i < 26; i++){
       if(d[i]) printf("Alphabet-%c Count-%d\n", 'a'+i, d[i]);
    }
    

    Corrected. Thanks caf and Leffler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to debug some homework but I am having trouble with these
I am having trouble correctly modeling related objects that can use templates. This is
I'm having trouble figuring out how to pass strings back through the parameters of
I am having trouble assigning the value of an NSString to a char *
EDITED: Updated 3/23/09. See rest of post at bottom. I'm still having trouble with
First, in order to provide full disclosure, I want to point out that this
A recent homework assignment I have received asks us to take expressions which could
Recently I have been studying recursion; how to write it, analyze it, etc. I
I've already asked 2 questions kind of related to this project, and i've reached

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.