473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 "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
2 1642
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Chris Readle | last post by:
Ok, I've just recently finished a beginning C class and now I'm working through K&R2 (alongside the C99 standard) to *really* learn C. So anyway, I'm working on an exercise in chapter one which...
16
by: Josh Zenker | last post by:
This is my attempt at exercise 1-10 in K&R2. The code looks sloppy to me. Is there a more elegant way to do this? #include <stdio.h> /* copies input to output, printing */ /* series of...
2
by: arnuld | last post by:
there is a solution on "clc-wiki" for exercise 1.17 of K&R2: http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_17 i see this uses pointers whereas K&R2 have not discussed pointers...
8
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
4
by: arnuld | last post by:
as i said, i have restarted the book because i overlooked some material. i want to have some comments/views on this solution. it runs fine, BTW. ------------------ PROGRAMME -------------- /*...
16
by: arnuld | last post by:
i have created solution which compiles and runs without any error/ warning but it does not work. i am not able to understand why. i thought it is good to post my code here for correction before...
19
by: arnuld | last post by:
this programme runs without any error but it does not do what i want it to do: ------------- PROGRAMME -------------- /* K&R2, section 1.6 Arrays; Exercise 1-13. STATEMENT: Write a program...
5
by: arnuld | last post by:
this is a programme that counts the "lengths" of each word and then prints that many of stars(*) on the output . it is a modified form of K&R2 exercise 1-13. the programme runs without any...
16
by: arnuld | last post by:
i am not able to make it work. it compiles without any error but does not work: what i WANTED: 1.) 1st we will take the input in to an array. (calling "getline" in "main") 2.) we will print...
88
by: santosh | last post by:
Hello all, In K&R2 one exercise asks the reader to compute and print the limits for the basic integer types. This is trivial for unsigned types. But is it possible for signed types without...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.