Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   K&R2 chapter 1, section 1.5.1 File Copying Question (http://www.velocityreviews.com/forums/t597319-k-and-r2-chapter-1-section-1-5-1-file-copying-question.html)

Jim Barlow 03-10-2008 03:12 AM

K&R2 chapter 1, section 1.5.1 File Copying Question
 
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.

santosh 03-10-2008 03:23 AM

Re: K&R2 chapter 1, section 1.5.1 File Copying Question
 
Jim Barlow wrote:

> 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.


Jim Barlow 03-10-2008 03:43 AM

Re: K&R2 chapter 1, section 1.5.1 File Copying Question
 
santosh wrote:
> Jim Barlow wrote:
>
>> 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.
>

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.

Richard Heathfield 03-10-2008 06:03 AM

Re: K&R2 chapter 1, section 1.5.1 File Copying Question
 
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:
<http://clc-wiki.net/wiki/K%26R2_solutions>
by the clc-wiki.net team.

> for Listing KRX113 Mr Heathfield repeatedly uses the phrase "text file".


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

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Micah Cowan 03-11-2008 04:01 AM

Re: K&R2 chapter 1, section 1.5.1 File Copying Question
 
santosh <santosh.k83@gmail.com> writes:

> Jim Barlow wrote:
>
>> 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".


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

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/

Jim Barlow 03-13-2008 02:07 AM

Re: K&R2 chapter 1, section 1.5.1 File Copying Question
 
Jim Barlow wrote:
> 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.


All times are GMT. The time now is 04:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.