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

A

arnuld

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&R2_solutions:Chapter_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 ?
 
M

mark_bluemel

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&R2_solutions:Chapter_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.
 
P

Peter Shaggy Haywood

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&R2_solutions:Chapter_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"?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
Best cryptoconsultant

Latest Threads

Top