Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: This blows my mind.

Reply
Thread Tools

Re: This blows my mind.

 
 
ext_u
Guest
Posts: n/a
 
      08-21-2003
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
 
Reply With Quote
 
 
 
 
Steve Zimmerman
Guest
Posts: n/a
 
      08-21-2003
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');
}
}





























 
Reply With Quote
 
 
 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      08-21-2003
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

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      08-22-2003
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 : http://www.velocityreviews.com/forums/(E-Mail Removed)
"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
 
Reply With Quote
 
ataru@nospam.cyberspace.org
Guest
Posts: n/a
 
      08-22-2003
Steve Zimmerman <(E-Mail Removed)> 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 |
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Netframework 1.1 install blows up Tom Beretvas ASP .Net 3 08-12-2005 09:53 PM
Firefox window blows up to more than screen size covering all Jim Firefox 5 06-01-2005 03:01 AM
Saving Excel document blows up Infragistics menu in frame Amy B ASP .Net 2 02-25-2005 08:37 PM
Re: Standby/Hibernate blows out wireless connection =?Utf-8?B?VGlt?= Wireless Networking 0 08-07-2004 09:55 PM
I.E. blows after running my app Gary ASP .Net 1 04-03-2004 05:01 PM



Advertisments