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