473,880 Members | 1,917 Online

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

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 "00000011111122 22333" 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
2 1675
On 23 Mar, 07:32, "arnuld" <geek.arn...@gm ail.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."

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 "00000011111122 22333" 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
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 "00000011111122 22333" what do they
represent ?
I don't know. At a guess, possibly the different digits represent
tens. Thus 000000111111222 222333 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!

"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 "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Mar 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.