mb1471 wrote:
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.