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 3281860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:51:47+00:00 2026-05-17T19:51:47+00:00

I have having some trouble printing a char from an ASCII value stored in

  • 0

I have having some trouble printing a “char” from an ASCII value stored in an array.

The goal overall is to read a string of input from the user, store that in an array. Then use another array to count the number of times each character appears in the string, storing the number of occurances in the array address that matches the ASCII code of the character being counted. Then to output that number of occurances along with which character was counted, and the percentage of characters.

I can successfully make the array of character occurances. And as a test I can do the counting and percentage calculations during the occurance count. But later when I try to make a FOR loop with a IF statement that ignores NULL values and prints the array address as the ASCII value for the character, the number of times the character occured, and the percentage that character appears of the total characters. I just get a NULL character printed. Below you find what I have written so far.

This is for help with a school assignment, and I am NOT asking for the solution in code. I’ve been trying to find out where I went wrong, and I’m not sure why one of my FOR loops works and the second one doesn’t. And would appreciate some help in finding where I’ve gone wrong.

#include <stdio.h>
#include <stdlib.h>
#define TERMINAL -9
int main()
{

float totalCharacters;
float currentCharacterCount;
int iteration, currentInputCharacter;
char checkCharacter, input [80];
int alphabetArray[128] = {0};

totalCharacters = 0;
iteration = 0;
currentCharacterCount = 0;
currentInputCharacter = 0;
alphabetArray[128] = 0;

printf("Enter a line of test: ");
gets(input);

printf ("FREQUENCY TABLE\n");
printf ("---------------\n");
printf ("Char Count %% of Total\n");
printf ("---- ----- ----------\n");

totalCharacters = strlen(input);

printf (" ALL %5d %9.2f%%\n", strlen(input), (totalCharacters / strlen(input)) * 100);

for ( iteration = 0; input[iteration] != '\0'; iteration++)
{
      checkCharacter = input[iteration];
      alphabetArray[checkCharacter]++;
      printf ("%4c %5d %9.2f%%\n", checkCharacter, alphabetArray[checkCharacter], ((float)alphabetArray[checkCharacter] / strlen(input)) * 100);
}

for ( iteration = 0; alphabetArray[iteration] != '\0'; iteration++)
{
     printf ("%1c ", alphabetArray[iteration]);

    if (alphabetArray[iteration] != '\0')
    {
       checkCharacter = alphabetArray[iteration];

       printf ("%4c %5d %9.2f%%\n", checkCharacter, alphabetArray[checkCharacter], ((float)alphabetArray[checkCharacter] / strlen(input)) * 100);
    }
}


system ("pause");
exit(0);

}
  • 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-17T19:51:48+00:00Added an answer on May 17, 2026 at 7:51 pm

    The Second for loop iterates over the alphabetArray which is NOT a string so is not terminated by ‘\0’.

    It would be better to use the fact that there are only 26 letter, and have an array 26 long. you can convert letters to position in the alphabet by somechar - 'a' for small letters and somechar - 'A' for capitals, though you would need to check for characters that aren’t in the range from ‘a’ to ‘z’ and ‘A’ to ‘Z’ such as !@£$%^&*().?.

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

Sidebar

Related Questions

Having some trouble passing values from one class to another. I basically have a
I'm having some trouble with a string that comes from a webpage having foreign
I have been having some trouble using RapidXML to parse a string. I receive
I have been having some real trouble with this for a while. I am
Im having some trouble writing a getstring function, this is what I have so
Im having some trouble getting the syntax right. I have a movie clip that
I'm having some trouble with an SQL statement that have to find the number
I'm having some trouble figuring out to call methods that I have in other
I'm having some trouble doing a very simple task. I have a rich textbox
I'm having some trouble with basic navigation between views. I have a tabBarController with

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.