Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: This blows my mind. (http://www.velocityreviews.com/forums/t314862-re-this-blows-my-mind.html)

ext_u 08-21-2003 02:13 AM

Re: This blows my mind.
 
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

Steve Zimmerman 08-21-2003 06:29 AM

Re: This blows my mind.
 
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[i] = 0;
while ((c = getchar()) != EOF)
if (c < 123)
++cc[c];
maxvalue = 0;
for (i = 97; i < 123; ++i)
if (cc[i] > maxvalue)
maxvalue = cc[i];

for (i = 97; i < 123; ++i) {
if (isprint(i))
printf("%5d - %c - %5d : ",
i, i, cc[i]);
else
printf("%5d - - %5d : ",
i, cc[i]);
if (cc[i] > 0) {
if ((len = cc[i] * MAXHIST / maxvalue) <= 0)
len = 1;
} else
len = 0;
while (len > 0) {
putchar ('*');
--len;
}
putchar('\n');
}
}






























Bruno Desthuilliers 08-21-2003 11:53 AM

Re: This blows my mind.
 
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


Richard Heathfield 08-22-2003 04:21 AM

Re: This blows my mind.
 
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 : binary@eton.powernet.co.uk
"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

ataru@nospam.cyberspace.org 08-22-2003 06:52 PM

Re: This blows my mind.
 
Steve Zimmerman <stevetux@sonic.net> broke the eternal silence and spoke thus:

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


> for (i = 97; i < 123; ++i)
> cc[i] = 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 |


All times are GMT. The time now is 09:08 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.