K&R2 chapter 1, section 1.5.1 File Copying Question

Discussion in 'C Programming' started by Jim Barlow, Mar 10, 2008.

  1. Jim Barlow

    Jim Barlow Guest

    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.
    Jim Barlow, Mar 10, 2008
    #1
    1. Advertising

  2. Jim Barlow

    santosh Guest

    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.
    santosh, Mar 10, 2008
    #2
    1. Advertising

  3. Jim Barlow

    Jim Barlow Guest

    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.
    Jim Barlow, Mar 10, 2008
    #3
  4. 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
    Richard Heathfield, Mar 10, 2008
    #4
  5. Jim Barlow

    Micah Cowan Guest

    santosh <> 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/
    Micah Cowan, Mar 11, 2008
    #5
  6. Jim Barlow

    Jim Barlow Guest

    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.
    Jim Barlow, Mar 13, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Herrcho
    Replies:
    6
    Views:
    436
    Peter Pichler
    Feb 20, 2004
  2. Peter Hansen
    Replies:
    2
    Views:
    895
    yaipa h.
    Jun 27, 2003
  3. Kim Enkovaara
    Replies:
    9
    Views:
    1,978
    diogratia
    Oct 16, 2008
  4. kampy
    Replies:
    9
    Views:
    318
    Steven D'Aprano
    Oct 19, 2012
  5. Aryeh M. Friedman
    Replies:
    34
    Views:
    549
    Aryeh M. Friedman
    Jan 7, 2013
Loading...

Share This Page