Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #13343

Re: Deleting first N lines from a text file

From blp@cs.stanford.edu (Ben Pfaff)
Newsgroups comp.lang.c
Subject Re: Deleting first N lines from a text file
Date 2011-11-14 16:36 -0800
Message-ID <87fwhqql0s.fsf@blp.benpfaff.org> (permalink)
References <469add1a-0497-4746-9c52-6c775ecd53d9@u5g2000vbd.googlegroups.com> <mub3c71nfmmvbvmcbndc29saadjo64t72e@4ax.com> <chine.bleu-EFA4DB.16310514112011@news.eternal-september.org>

Show all headers | View raw


Acid Washed China Blue Jeans <chine.bleu@yahoo.com> writes:

> In article <mub3c71nfmmvbvmcbndc29saadjo64t72e@4ax.com>,
>  Roberto Waltman <usenet@rwaltman.com> wrote:
>
>> pozz  wrote:
>> >I want to delete the first N lines from a file text.
>> >...
>> >The second approach is simpler,...
>> >...
>> >What do you think about those thoughts?
>> 
>> Only that the second approach is not simpler.
>> Also, depending on the underlying OS, it may not be possible to read
>> from and write to the same file as you propose.
>
> Fopen with "r+". If fopen succeeds, the library has promised
> you you are allowed to read and write an existing file.

However, writing in a text file may truncate it, see 7.19.3
"Files":

     Whether a write on a text stream causes the associated file
     to be truncated beyond that point is implementation-defined.
-- 
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
 \n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Deleting first N lines from a text file pozz <pozzugno@gmail.com> - 2011-11-14 16:02 -0800
  Re: Deleting first N lines from a text file Roberto Waltman <usenet@rwaltman.com> - 2011-11-14 19:21 -0500
    Re: Deleting first N lines from a text file Acid Washed China Blue Jeans <chine.bleu@yahoo.com> - 2011-11-14 16:31 -0800
      Re: Deleting first N lines from a text file blp@cs.stanford.edu (Ben Pfaff) - 2011-11-14 16:36 -0800
      Re: Deleting first N lines from a text file Roberto Waltman <usenet@rwaltman.com> - 2011-11-14 20:10 -0500
      Re: Deleting first N lines from a text file Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-11-16 11:04 +0200
  Re: Deleting first N lines from a text file gordonb.3hlvm@burditt.org (Gordon Burditt) - 2011-11-14 18:53 -0600
  Re: Deleting first N lines from a text file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-14 22:06 -0500
    Re: Deleting first N lines from a text file Giuseppe <giuseppe.modugno@gmail.com> - 2011-11-15 16:57 -0800
      Re: Deleting first N lines from a text file Keith Thompson <kst-u@mib.org> - 2011-11-15 17:50 -0800
        Re: Deleting first N lines from a text file pozz <pozzugno@gmail.com> - 2011-11-15 23:11 -0800
          Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 04:11 -0800
      Re: Deleting first N lines from a text file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 21:48 -0500
        Re: Deleting first N lines from a text file pozz <pozzugno@gmail.com> - 2011-11-15 23:14 -0800
          Re: Deleting first N lines from a text file "BartC" <bc@freeuk.com> - 2011-11-16 14:26 +0000
            Re: Deleting first N lines from a text file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-16 21:32 -0500
              Re: Deleting first N lines from a text file Ian Collins <ian-news@hotmail.com> - 2011-11-17 15:43 +1300
                Re: Deleting first N lines from a text file "BartC" <bc@freeuk.com> - 2011-11-17 10:35 +0000
                Re: Deleting first N lines from a text file Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-16 07:05 +0000
              Re: Deleting first N lines from a text file Robert Wessel <robertwessel2@yahoo.com> - 2011-11-16 22:46 -0600
      Re: Deleting first N lines from a text file gordonb.pa5u0@burditt.org (Gordon Burditt) - 2011-11-16 16:28 -0600
        Re: Deleting first N lines from a text file Kaz Kylheku <kaz@kylheku.com> - 2011-11-16 22:53 +0000
          Re: Deleting first N lines from a text file gordonb.z5i2o@burditt.org (Gordon Burditt) - 2011-11-16 18:34 -0600
  Re: Deleting first N lines from a text file jacob navia <jacob@spamsink.net> - 2011-11-15 12:48 +0100
    Re: Deleting first N lines from a text file "-.-" <none@none.none> - 2011-11-16 14:01 +0100
      Re: Deleting first N lines from a text file jacob navia <jacob@spamsink.net> - 2011-11-16 14:44 +0100
        Re: Deleting first N lines from a text file tom st denis <tom@iahu.ca> - 2011-11-17 10:43 -0800
          Re: Deleting first N lines from a text file jt@toerring.de (Jens Thoms Toerring) - 2011-11-18 23:12 +0000
  Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 06:42 -0800
    Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 07:43 -0800
    Re: Deleting first N lines from a text file Keith Thompson <kst-u@mib.org> - 2011-11-16 11:13 -0800
      Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 13:50 -0800

csiph-web