K&R2 chapter 1, section 1.5.1 File Copying Question

J

Jim Barlow

Does anyone know why K&R2 uses the term "File Copying" at this point
(1.5.1)?
Also, in the K&R2 answers to exercises maintained by Richard Heathfield,
for Listing KRX113 Mr Heathfield repeatedly uses the phrase "text file".
This comes well before what I have understood to be "files" are
introduced in the book.
 
S

santosh

Jim said:
Does anyone know why K&R2 uses the term "File Copying" at this point
(1.5.1)?

It might more accurately be called as "stream copying". The probably use
the term file copying because under UNIX all devices are represented
as "files".
Also, in the K&R2 answers to exercises maintained by Richard
Heathfield, for Listing KRX113 Mr Heathfield repeatedly uses the
phrase "text file". This comes well before what I have understood to
be "files" are introduced in the book.

I suppose he is using the term "text file" in it's more commonly
understood meaning in computing, not it's C specific one.
 
J

Jim Barlow

santosh said:
It might more accurately be called as "stream copying". The probably use
the term file copying because under UNIX all devices are represented
as "files".


I suppose he is using the term "text file" in it's more commonly
understood meaning in computing, not it's C specific one.
Thank you, that clears up the question regarding the K&R book.
I hope Mr. Heathfield will explain his comments in his solution in
Listing KRX113. That one still has me confused.
 
R

Richard Heathfield

Jim Barlow said:
Does anyone know why K&R2 uses the term "File Copying" at this point
(1.5.1)?
Also, in the K&R2 answers to exercises maintained by Richard Heathfield,

I don't maintain any such site, and have not done so for years (although
the site is still up, which is astounding since the account was closed
several years ago). The solutions are now maintained at this page:
for Listing KRX113 Mr Heathfield repeatedly uses the phrase "text file".

Only in an introductory comment which you can in fact ignore completely.
 
M

Micah Cowan

santosh said:
It might more accurately be called as "stream copying". The probably use
the term file copying because under UNIX all devices are represented
as "files".

All devices, yeah, but not all streams (cf pipes, for example).
 
J

Jim Barlow

Jim said:
Does anyone know why K&R2 uses the term "File Copying" at this point
(1.5.1)?
Also, in the K&R2 answers to exercises maintained by Richard Heathfield,
for Listing KRX113 Mr Heathfield repeatedly uses the phrase "text file".
This comes well before what I have understood to be "files" are
introduced in the book.

Reading Stephen Prata's "C Primer Plus", in chapter 8 "Redirection and
Files", I found:

"Unix, Linux, and current DOS versions enable you to redirect both input
and output. Redirecting input enables your program to use a file instead
of the keyboard for input, and redirecting output enables it to use a
file instead of the screen for output."

So to get the program to use a text file as input I would use:
"my_program < text_file"

This is the answer I was looking for. I thank Santosh and Richard
Heathfield for taking the time to reply to my question.

Talking about this with a co-worker today, I learned more about OUTPUT
redirection. If I use "my_program > output_file" the "output_file" will
be created or, if it already exists, will be overwritten. If I use TWO
redirection symbols (">>") then the output from "my_program" will be
appended to "output_file" (assuming it already exists).

I already knew about simple redirection but failed to connect it with
the problem I was having with the K&R examples and exercises. I hope
this helps other newbies learning C using K&R2.
 

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
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top