473,796 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

K&R2 1.6 Arrays, exercise 1-13 (vertical histogram)

i was able to create a solution for a Horizontal-Histogram. i was
completely unable to understand this Vertical-Histogram phenomenon.
even though i have looked at the solution at this page:

http://clc-wiki.net/wiki/K%26R2_solu..._1:Exercise_13

still i am not able to make sense of many-many things like (on the
same page) for my solution i have written this in documentation,t o
give reader some hint about what i thought before coding:
METHOD:
1.) we will count the length of each word by counting the
characters it has.

2.) we use an array where we will keep track of how many words
of a specific length we have encountered.

3.) for simplicity, we will not take into account any words
having more than 10 characters in it. extra characters will
simply be discarded.

*/

and this:

int i = 0;
int j =0; /* i and j are simply index counters */
int c = 0;
int nchar = 0; /* number of characters in a word */
int inspace = IN; /* a flag to know whether we are inside of outside
the word */
int wordlen[MAXLENGTH]; /* counts how many words of a particular
length we have seen */
but the Vertical-Histogram solution doe snot given any hints in
variables. completely alien kind of thing for me. does that mean i
should leave programming and do something else like carpentry or
selling water purifiers :-(

Apr 4 '07
12 4497
On Apr 5, 2:35 am, "arnuld" <geek.arn...@gm ail.comwrote:
On Apr 5, 12:58 am, "user923005 " <dcor...@connx. comwrote:
Why not think up your own solution to K&R exercise 1-13?

this is all i can do:

#include<stdio. h>

int main()
{
return 0;

}
Have you covered arrays yet?

not sure what you mean. i am at chapter 1, so i know only this:

type arr[size];

"arr" is an array of type "type" and "size" tells the number of
elements it has. that's it.
It is just that the problem is trivial with 2-d arrays. I guess that
you did not get there yet.

Apr 5 '07 #11
Flash Gordon said:

<snip>
The most serious complaints I have on your code are that you are not
checking for overflow on your counts,
Mm-hmmm...
passing a long to printf having told it to expect an int!
WHAT?
| long thisval = 0;
<snip>
| printf("%4d | ", thisval);
Oh deary deary me. You do have a point, don't you!

Your output will also be messed up if you have too many of a given
word length.
Aye.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 5 '07 #12
arnuld wrote:
>
.... snip ...
>
i compile my code with this:

gcc -ansi -pedantic -Wall -Wextra -O input.c

but if you say "-std=c99" is a better idea then i will do that.
In general, it is not a better idea. Most people are using C90 or
C95 compilers. K & R is written to that standard.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Apr 7 '07 #13

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

Similar topics

12
2179
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 give me strange behavior. Here is the code I've written: /****************************************************************************** * K&R2 Exercise 1-9 * Write a program to copy its input to its output, replacing strings of blanks * with a...
16
2282
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 blanks as a single one */ int main() { int c;
2
2297
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 yet. i have created a solution myself by modifying the example programme of section 1.19. i tried to find the source-code of K&R2 using Google. i found the home
8
4764
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. --------------------------------- PROGRAMME -------------------------------- /* K&R2 section 1.9 exercise 1.19
12
2224
by: arnuld | last post by:
this is exercise 2-3 from the mentioned section. i have created a solution for it but i see errors and i tried to correct them but still they are there and mostly are out of my head: ------------------------------- PROGRAMME -------------------------- /* Section 2.7 type conversions we are asked to write a function "htoi(an array)" that accomplishes this:
4
1572
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 -------------- /* K&R2 section 1.5.3, exercise 1-8 write a programme to count blanks, tabs and newlines */
16
1815
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 looking at CLC-Wiki for K&R2 solutions: --------------- PROGRAMME ------------ /* K&R2 section 1.5.3, exercise 1-9 STATEMENT: write a programme to copy its input to output replacing
16
1741
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 that input array on terminal. (in "main") 3.) we will reverse the array. (calling "reverse" in "main") 4.) we will print that reversed array. (in "main")
88
3803
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 invoking undefined behaviour triggered by overflow? Remember that the constants in limits.h cannot be used.
13
183
by: Richard Heathfield | last post by:
arnuld said: What do you think that line does? For my own part, I can make no sense whatsoever out of it. -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.