k&r line count

M

mb1471

In the C programming language by K&R: In section 1.9 there is great
focus on the line-count program and many of the problems at the end of
that section involve editing it. Yet when I go to debug the program, I
cannot figure out how you are supposed to input the text that it is
dealing with.

For those who haven't read the book, the input is recieved by the
getchar() method. How do I enter text into the program to test the line
count and other similar programs?
 
V

Vladimir S. Oka

mb1471 opined:
In the C programming language by K&R: In section 1.9 there is great
focus on the line-count program and many of the problems at the end
of that section involve editing it. Yet when I go to debug the
program, I cannot figure out how you are supposed to input the text
that it is dealing with.

For those who haven't read the book, the input is recieved by the
getchar() method. How do I enter text into the program to test the
line count and other similar programs?

It would've still be helpful if you posted at least a snippet.

If the only input is using `getchar()`, then it's accepted from
`stdin`. Usual ways is typing on the keyboard or redirecting from a
file. The latter will depend on your particular OS.
 
S

santosh

mb1471 said:
In the C programming language by K&R: In section 1.9 there is great
focus on the line-count program and many of the problems at the end of
that section involve editing it. Yet when I go to debug the program, I
cannot figure out how you are supposed to input the text that it is
dealing with.

For those who haven't read the book, the input is recieved by the
getchar() method. How do I enter text into the program to test the line
count and other similar programs?

Firstly, in C parlance, methods are called functions.
Coming to your problem, getchar() takes it's input from the standard
input stream. Unless it has been redirected, it will be your keyboard.
Therefore, you can type in the words directly. Another method is to use
your operating system's redirection facilities and redirect a disk file
to your program. The exact syntax for doing this varies for each system
so read it's manual. Usually you can do:

your_program < disk_file

This will cause your program, (and hence getchar()), to process the
contents of disk_file as if it were stdin. But don't try to specify
anything other than a text file.
 

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

K&R 1-24 15
K$R xrcise 1-13 (histogram) 4
How to keep count of right answer and wrong answers in C++? 0
K&R Exercise 1-21: entab 10
Struggling with K&R 12
K&R exercise 1-18 10
K&R Exercise 6-2 8
1-17 in K&R book 9

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top