Re: This blows my mind.

Discussion in 'C Programming' started by ext_u, Aug 21, 2003.

  1. ext_u

    ext_u Guest

    I do know what a histogram is.

    My point was that how in the world do they expect me to make on having
    just shown me how to set the values for arrays ( and doing a skim job
    at that ).

    A couple of you showed me some code for creating a histogram using
    values and commands that havent even been covered in the book yet. So
    I guess you proved my point even more. I am still going at the book
    tho. Trying to figure out how to do it one thing at a time.

    I posted my code in another thread, I was having trouble getting the
    program to recognize what an actual word was.

    Thanks,
    Henry
    ext_u, Aug 21, 2003
    #1
    1. Advertising

  2. ext_u wrote:

    > I do know what a histogram is.
    >
    > My point was that how in the world do they expect me to make on having
    > just shown me how to set the values for arrays ( and doing a skim job
    > at that ).
    >
    > A couple of you showed me some code for creating a histogram using
    > values and commands that havent even been covered in the book yet. So
    > I guess you proved my point even more. I am still going at the book
    > tho. Trying to figure out how to do it one thing at a time.
    >
    > I posted my code in another thread, I was having trouble getting the
    > program to recognize what an actual word was.
    >
    > Thanks,
    > Henry
    >


    Henry, I admire your courage in seeking help from comp.lang.c.
    I went through just what you're going through. Persevere; it's
    worth it.

    --Steve


    /* just enter lower case alphabet, then Control-d when done */

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

    #define MAXHIST 15 /* max length of histogram */

    /* print horizontal histogram freq. of different characters */
    main()
    {
    int c, i;
    int len; /* length of each bar */
    int maxvalue; /* maximum value for cc[] */
    int cc[26]; /* character counters */

    for (i = 97; i < 123; ++i)
    cc = 0;
    while ((c = getchar()) != EOF)
    if (c < 123)
    ++cc[c];
    maxvalue = 0;
    for (i = 97; i < 123; ++i)
    if (cc > maxvalue)
    maxvalue = cc;

    for (i = 97; i < 123; ++i) {
    if (isprint(i))
    printf("%5d - %c - %5d : ",
    i, i, cc);
    else
    printf("%5d - - %5d : ",
    i, cc);
    if (cc > 0) {
    if ((len = cc * MAXHIST / maxvalue) <= 0)
    len = 1;
    } else
    len = 0;
    while (len > 0) {
    putchar ('*');
    --len;
    }
    putchar('\n');
    }
    }
    Steve Zimmerman, Aug 21, 2003
    #2
    1. Advertising

  3. ext_u wrote:
    > I do know what a histogram is.
    >
    > My point was that how in the world do they expect me to make on having
    > just shown me how to set the values for arrays ( and doing a skim job
    > at that ).
    >
    > A couple of you showed me some code for creating a histogram using
    > values and commands that havent even been covered in the book yet. So
    > I guess you proved my point even more.


    No, because you don't need the functions and constructs used in the code
    you're talking about to do this exercise. I did it a few years ago, only
    using what you're supposed to know at this stage (and well, I didn't
    know much more at that time...). The only things you need to know to
    'draw' an histogram on a text output is how to print a character on a
    text output, and how to loop.


    Bruno
    Bruno Desthuilliers, Aug 21, 2003
    #3
  4. Steve Zimmerman wrote:

    > Henry, I admire your courage in seeking help from comp.lang.c.


    Yes, it can be very dangerous seeking help here, since there's no guarantee
    of the quality of the help you receive.

    > I went through just what you're going through. Persevere; it's
    > worth it.


    That, at least, I can agree with.

    > for (i = 97; i < 123; ++i)


    Assuming a particular character set here is not only non-portable but also
    completely unnecessary. Henry hasn't mentioned what system he is using, as
    far as I know, so I see no justification for making non-portable
    assumptions about his character set. I also see no reason for selecting out
    this particular range of characters. The spec says nothing about them.

    If you respond, please show that you're all growed up, by responding
    intelligently instead of just conforming to type (as per your recent
    "contributions" to this thread). Thank you.

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
    Richard Heathfield, Aug 22, 2003
    #4
  5. ext_u

    Guest

    Steve Zimmerman <> broke the eternal silence and spoke thus:

    > int cc[26]; /* character counters */


    > for (i = 97; i < 123; ++i)
    > cc = 0;


    This doesn't look right... cc has 26 elements, so accessing elements 97
    through 123 of cc sounds like a bad plan. Perhaps you wanted cc[i%26]?

    --
    Christopher Benson-Manica | Jumonji giri, for honour.
    ataru(at)cyberspace.org |
    , Aug 22, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Beretvas

    Netframework 1.1 install blows up

    Tom Beretvas, Jul 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    689
    Tom Beretvas
    Aug 12, 2005
  2. Gary

    I.E. blows after running my app

    Gary, Apr 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    306
    Alvin Bruney [MVP]
    Apr 3, 2004
  3. Amy B
    Replies:
    2
    Views:
    553
    Guest
    Feb 25, 2005
  4. clintonG
    Replies:
    2
    Views:
    583
    clintonG
    Nov 11, 2005
  5. Re: This blows my mind.

    , Aug 20, 2003, in forum: C Programming
    Replies:
    7
    Views:
    522
    Peter Shaggy Haywood
    Aug 24, 2003
Loading...

Share This Page