473,396 Members | 2,151 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&r line count

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?

Mar 25 '06 #1
2 1706
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.

--
BR, Vladimir

"I don't object to sex before marriage, but two minutes before?!?"

Mar 25 '06 #2
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.

Mar 25 '06 #3

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

Similar topics

10
by: Des Small | last post by:
Lately I have found myself using a pattern to make new dictionaries quite often, by which I mean twice: def invert(d): nd = {} ).append(key) for k, v in d] return nd def count(l): d = {}
7
by: sathyashrayan | last post by:
Group, Following function will check weather a bit is set in the given variouble x. int bit_count(long x) { int n = 0; /* ** The loop will execute once for each bit of x set,
2
by: tvn007 | last post by:
Please help why this code not compile I would like it to be something like this: istringstream stringstreams(line); stringstreams>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;...
10
by: Eric | last post by:
Hello, I have been working through the K&R book (only chapter one so far) examples and exercises. After much sweat and hair pulling, I think I have a solution for ex 1-18 on page 31. It...
5
by: ducky801 | last post by:
Hi all. When i run the code below i get a 'NullReferenceException was unhandled' error. I am using VB 2005 Express. I'm confused about this because, I have declared my array and i'm trying to...
11
by: c19h28o2 | last post by:
Hi, Guy's I know there are several posts about this, however I do not want to read them as answers are undoubtedly posted! Here is my attempt but I'm slightly stuck. I'm not looking for the...
19
by: pkirk25 | last post by:
I wonder if anyone has time to write a small example program based on this data or to critique my own effort? A file called Realm List.html contains the following data: Bladefist-Horde...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
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...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...

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.