help me! -- K&R exercise 1-11

L

leonard greeff

I want to know the correct way to answer exercise 1-11 of K&R.
The only bug that I can find is that nw counts one to many words.
(if there are 8 words, nw will be 9) Am I correct aor is there
more to it

leonard
 
I

Irrwahn Grausewitz

leonard greeff said:
I want to know the correct way to answer exercise 1-11 of K&R.
The only bug that I can find is that nw counts one to many words.
(if there are 8 words, nw will be 9)
Are you sure?
Hint: To test a program, I would compile and run it...

Regards

Irrwahn
 
T

Thomas Matthews

leonard said:
I want to know the correct way to answer exercise 1-11 of K&R.
The only bug that I can find is that nw counts one to many words.
(if there are 8 words, nw will be 9) Am I correct aor is there
more to it

leonard

Your problem is in the "for" loop. The loop should count
from zero to "nw < 9".

If that doesn't work, post your code along with the error
message from the compiler, or stating the actual results
and the expected results.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
I

Irrwahn Grausewitz

Thomas Matthews said:
Your problem is in the "for" loop. The loop should count
from zero to "nw < 9".

If that doesn't work, post your code along with the error
message from the compiler, or stating the actual results
and the expected results.

In the copy of K&R2 I own there is no "for"-loop in sample program
1.5.4, which is the one exercise 1.11 refers to...

Regards

Irrwahn
 
A

amanayin

leonard said:
I want to know the correct way to answer exercise 1-11 of K&R.
The only bug that I can find is that nw counts one to many words.
(if there are 8 words, nw will be 9) Am I correct aor is there
more to it

leonard

This answer was taken from The C answer book by
Clovis L Tondo & Scott E Gimpel
which gives all the answers to K&R

To test the word count program first try no input,
The output should be: 0 0 0 (zero newlines, zero words, zero characters).
Then try a one-character word. The output should be: 1 1 2.
(one new line,one word, two characters-a letter followed by
a new line character). Then try a two character word.
the output should be: 1 1 3 (one new line, one word,
three chacters- two chacters followed by a new line character).
In addition, try 2 one-chacter words (the output should be 1 2 4) and
2 one-character words-one word per line(the output should be 2 2 4).
The kinds of input most likely to uncover bugs are those that test boudary
conditions. Some boundaries are:

-no input
-no words-just new lines
-no words-just blanks, tabs, and newlines
-one word per a line-no blanks and tabs
-word starting at the beginning of the line
-word starting after some blanks
 
A

amanayin

leonard said:
I want to know the correct way to answer exercise 1-11 of K&R.
The only bug that I can find is that nw counts one to many words.
(if there are 8 words, nw will be 9) Am I correct aor is there
more to it

leonard

This answer was taken from The C answer book by
Clovis L Tondo & Scott E Gimpel
which gives all the answers to K&R

To test the word count program first try no input,
The output should be: 0 0 0 (zero newlines, zero words, zero characters).
Then try a one-character word. The output should be: 1 1 2.
(one new line,one word, two characters-a letter followed by
a new line character). Then try a two character word.
the output should be: 1 1 3 (one new line, one word,
three chacters- two chacters followed by a new line character).
In addition, try 2 one-chacter words (the output should be 1 2 4) and
2 one-character words-one word per line(the output should be 2 2 4).
The kinds of input most likely to uncover bugs are those that test boudary
conditions. Some boundaries are:

-no input
-no words-just new lines
-no words-just blanks, tabs, and newlines
-one word per a line-no blanks and tabs
-word starting at the beginning of the line
-word starting after some blanks
 
L

leonard greeff

amanayin said:
leonard greeff wrote:




This answer was taken from The C answer book by
Clovis L Tondo & Scott E Gimpel
which gives all the answers to K&R

To test the word count program first try no input,
The output should be: 0 0 0 (zero newlines, zero words, zero characters).
Then try a one-character word. The output should be: 1 1 2.
(one new line,one word, two characters-a letter followed by
a new line character). Then try a two character word.
the output should be: 1 1 3 (one new line, one word,
three chacters- two chacters followed by a new line character).
In addition, try 2 one-chacter words (the output should be 1 2 4) and
2 one-character words-one word per line(the output should be 2 2 4).
The kinds of input most likely to uncover bugs are those that test boudary
conditions. Some boundaries are:

-no input
-no words-just new lines
-no words-just blanks, tabs, and newlines
-one word per a line-no blanks and tabs
-word starting at the beginning of the line
-word starting after some blanks

ahhh! I see, thanks.
 

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

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,207
Latest member
HelenaCani

Latest Threads

Top