By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,486 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,486 IT Pros & Developers. It's quick & easy.

K&R2, section1.6, exercise 1-14

P: n/a
i was not even able to understand how should i proceed tow rite
solution for this exercise:

"Write a program to print a histogram of the frequencies of different
characters in its input."

then i tried this: http://clc-wiki.net/wiki/K%26R2_solu..._1:Exercise_14

i did not understand the following in Histogram solution:

1.) on X-axis, all i see are "0000001111112222333" what do they
represent ?
2.) Y-axis, starts from 0 and goes to 476, whereas there are only 256
characters in ASCII.

i guess, Y-axis represents how many times a character occurs but how
do i know how many times 'a' occured and how many times "?" occured or
how many times a particular "character" occured ?

Mar 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 23 Mar, 07:32, "arnuld" <geek.arn...@gmail.comwrote:
i was not even able to understand how should i proceed tow rite
solution for this exercise:

"Write a program to print a histogram of the frequencies of different
characters in its input."
As ever, it's helpful to break a task into sub-tasks.

Start off by considering how you would write a program which simply
counted the frequencies of different characters and did a simple
report like :-

character 0 occurred 0 times
character 1 occurred 3 times
....
character 255 occurred 0 times

Then consider how to do the histogram.
then i tried this:http://clc-wiki.net/wiki/K%26R2_solu..._1:Exercise_14

i did not understand the following in Histogram solution:

1.) on X-axis, all i see are "0000001111112222333" what do they
represent ?
Character in decimal numeric form printed vertically...

Non-occurring characters are not plotted

2.) Y-axis, starts from 0 and goes to 476, whereas there are only 256
characters in ASCII.

i guess, Y-axis represents how many times a character occurs but how
do i know how many times 'a' occured and how many times "?" occured or
how many times a particular "character" occured ?
That's what we are maintaining in the freqarr array, using the same
sort of approach which was used in the word length exercise.

Mar 23 '07 #2

P: n/a
Groovy hepcat arnuld was jivin' on 23 Mar 2007 00:32:47 -0700 in
comp.lang.c.
K&R2, section1.6, exercise 1-14's a cool scene! Dig it!
>i was not even able to understand how should i proceed tow rite
solution for this exercise:

"Write a program to print a histogram of the frequencies of different
characters in its input."
Use an array of int, each element representing a character.
Initialise all elements to 0. When you read a character, increment the
coresponding element of the array.
>then i tried this: http://clc-wiki.net/wiki/K%26R2_solu..._1:Exercise_14

i did not understand the following in Histogram solution:

1.) on X-axis, all i see are "0000001111112222333" what do they
represent ?
I don't know. At a guess, possibly the different digits represent
tens. Thus 000000111111222222333 might represent 35, but only an
approximation.
>2.) Y-axis, starts from 0 and goes to 476, whereas there are only 256
characters in ASCII.
No, ASCII is a 7 bit characer set. There are 128 values in it, the
first 32 of which are control characters (including NUL, the null
character).
>i guess, Y-axis represents how many times a character occurs but how
do i know how many times 'a' occured and how many times "?" occured or
how many times a particular "character" occured ?
I don't know.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Mar 26 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.