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


Groups > comp.lang.c > #13606

Re: Deleting first N lines from a text file

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: Deleting first N lines from a text file
Date 2011-11-18 23:12 +0000
Organization Freie Universitaet Berlin
Message-ID <9io73qFr8eU1@mid.uni-berlin.de> (permalink)
References <469add1a-0497-4746-9c52-6c775ecd53d9@u5g2000vbd.googlegroups.com> <j9tjj6$5qs$1@speranza.aioe.org> <ouOwq.98707$GZ3.71424@tornado.fastwebnet.it> <ja0eoc$fee$1@speranza.aioe.org> <32da6a36-4b7a-4e41-8ee2-957fef4814b8@y42g2000yqh.googlegroups.com>

Show all headers | View raw


tom st denis <tom@iahu.ca> wrote:
> On Nov 16, 8:44 am, jacob navia <ja...@spamsink.net> wrote:
> > Le 16/11/11 14:01, -.- a écrit :
> >
> > > jacob navia was trying to save the world with his stuff:
> >
> > >> Using the containers library (and if your file fits in memory)
> >
> > >> #include <containers.h>
> >
> > > You self-celebrating fucko.
> >
> > That is why you hide behind a pseudo, because you have the courage of
> > your opinions...

> While rude the guy has a point.  You can accomplish this goal easily
> with something like

> #include <stdio.h>
> #include <stdlib.h>

> int main(int argc, char **argv)
> {
>    int skip;
>    char buf[2048];
>    skip = 0;
>    if (argc == 2) {
>       skip = atoi(argv[1]);
>    }
>    while (skip-- && fgets(buf, sizeof buf, stdin) != NULL);
>    while (fgets(buf, sizeof buf, stdin) != NULL) {
>       fputs(buf, stdout);
>    }
>    return 0;
> }

> This doesn't require buffering the entire file, it's way more
> portable, it's about the same length as your original "solution," etc.

> IOW you're just posting to advertise your wares... in a C group where
> your offerings are not C....

> Stop spamming USENET and maybe people will treat you better.

I don't understand your complaints. As far as I can see Mr. Navia's
container library is written in standard compliant C - I just tried
to compile his program after minor modifications (added an include
for <stdio.h> and replaced the angle brackets around "containers.h"
by double quotes since the header file isn't in the systems include
directory on my system) with

gcc -std=c99 -pedantic -Wextra -Wall -Wwrite-strings

and there were no complaints at all. For C89 the main complaint
was the missing support for the 'long long' type used in the
library and a few minor niggles about two '//' comments in the
'containers.h" header file and about mixing of declarations and
code, finally, the missing return statement at the end - nothing
of any seriousness. (And if you try to compile the library it-
self in strict C89 mode all the compilers complaints seem to be
on the same level of seriousness, i.e. very low and not diffi-
cult to address.)

Further, the library is under a very permissive license, BSD,
so there are no strings attached.

So all I can see is that Mr. Navia proposed to use a library,
written by him and made available to the public, as a possible
solution for the problem the OP has. He didn't even mention
were his container library can be found - if the OP or others
are interested it's at 

http://code.google.com/p/ccl/

If that is spamming then a lot of other posters in this group
are guilty of the same when they dare to mention that they have
written some functions or library others might use freely for a
problem they want to solve. Just because Mr. Navia is also the
author of a compiler you can pay him money for IMHO shouldn't
bare him from mentioning code he wrote and made available for
free and taking part in trying to help others, or should it?

The only valid point I can see in your post is the question if
it's an optimal solution having to read in all of the file into
memory. But then this was already explicitly pointed out by Mr.
Navia himself as a requirement (and thus a possible shortcoming)
of using his solution - and for a lot of cases I don't think it's
a complete showstopper.

On the other hand your solution doesn't address the second re-
quirement of the OP, i.e. that the input file itself is to be
changed on exit of the program - your program reads from stdin
and writes to stdout, so it's a simple filter. In contrast, Mr.
Navia's program does also handle this other requirement of the
OP in changing the input file itself with a very similar number
of lines of code the user has to type...

Finally, I've got to say that I find Mr. Navia's solution rather
easy to comprehend without even having read the documentation for
his library (which I will do now;-). It seems to be a rather nice
example of how using it could make writing as well as understanding
certain types of programs in C quite a bit easier.

                               Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

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