Thread: Histogram

  1. #1
    Registered User
    Join Date
    Oct 2018

    Post Histogram

    Here is the question :

    This is my code that I have made :

    #include <stdio.h>
    #include <string.h>
    void count(char str[]);
    int main()
        char text[80];
        printf("Enter a string : ");
        return 0;
    void count(char str[])
        int i, j, count;
        for (i = 0; str[i] != '\0'; i++)
            count = 0;
            for (j = 0; str[j] != '\0'; j++)
                if (str[j] == str[i])
            printf("%c : %d\n", str[i], count);
    My question is, how can i print the character in a type of an array based on their alphabetical arrangement ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    First, posting "Hi, i wonder that you can help me to solve my problem. please !" as your title for every post isn't helpful.

    > char text[80];
    > printf("Enter a string : ");
    > gets(text);
    1. Your input lines are up to 1000 characters.
    2. There is no mention of prompting for input.
    3. Your first line of input is the number of test cases. These programs are tested automatically, so you need to follow the input file spec closely.
    4. NEVER EVER use gets(). It is totally unsafe. It's even been removed from the latest C standard. Use fgets() instead.

    I suppose you can start with understanding how this works.
    int counters[26] = { 0 };
    char c = 'B';  // for example
    counters[c - 'A']++;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Histogram
    By SpecKROELLchen in forum C Programming
    Replies: 9
    Last Post: 08-02-2012, 03:10 AM
  2. Histogram help
    By Fixxxer in forum C Programming
    Replies: 4
    Last Post: 11-12-2010, 02:15 AM
  3. histogram
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 04-04-2007, 12:25 PM
  4. histogram equilization alg.
    By sunoflight77 in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2005, 01:05 AM
  5. Histogram
    By fjf314 in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2004, 11:39 PM

Tags for this Thread