Re: Code Review - is this code ***
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Tue, 04 Aug 2009 10:18:28 +0000
spinoza1111 said:
On Aug 2, 11:09 pm, "Dennis" <nojunkm...@xxxxxxxxxxxx> wrote:news:290e435e-9892-4245-90c8-ac53dde11d80@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"spinoza1111" <spinoza1...@xxxxxxxxx> wrote in message
<snip>
Rilly? OK, smartass, what separates two lines in a file? Linefeed
(\x10)? or carriage return and line feed (\x13x10)?
C may have a symbol for this. Richard thinks these symbols are the
answer. Of course, they have to be set correctly, and when the
program is compiled the program's opinion as to line division is
cast in concrete.
Try writing some programs to perform line-based I/O in it and
compile the programs on Unix or Linux and Windows. You'll then find
that...you don't have to worry about it.
Yes indeed. Who cares if it's correct?
Some programmers care, and others don't. If you have a genuine text
file, you can use text-based functions to read it, and let the
platform worry about the on-disk representation. That's called
"abstraction", and it's a good thing.
This is C!!
Yes. As with any programming language, some of its users care about
correctness, and others don't.
Furthermore, in C detection of the Windows-convention line break
has to use a different function than detection of the Linux
convention. So this is portable how?
Yes, you can write a routine to detect the separator. Lovely.
Or usefgets.
Looks like you just did, cowboy: you seem to have lost a space
between "use" and "fgets".
The original <4a75ae52$1@xxxxxxxxxxxxxx> has the space there. Looks
like you made an unjustified accusation again.
From wikipedia:
Here we prefer to rely on facts, not wikipedia.
<snip>
To do so I would shitcan fgets. I'd read the entire file into memory
up to a bound, and use a simple blocking scheme for bigger files.
I'd scan for runs of nongraphic characters and assume that these
were meant to be line separators.
In other words, you'd re-invent strings(1).
I'd wind up with a tool that could be used to recover the data in
Word files when Word is unavailable. Thousand and one uses. Hours of
fun.
Yes, that's why it was written in the first place. And, for its
purpose, it works just fine. And if that is all you want to do with
text files, that's fine too.
I sure as hell would not use fgets to get some creep's opinion as to
what constitutes line separation.
Not everybody is an fgets fan. I'm not, for instance. But I'm not a
vehement opponent thereof either, and I do use it from time to time,
especially in exegetic code.
This is because the most general
definition of a text file in practice and in the Anglophone world is
a series of characters that appear on common keyboards in the USA.
The program would be a clear definition of what constitutes a text
file.
One might argue (and some people do argue) that there is no such thing
as a disparity between "text file" and "binary file", and that what
we really have is two different ways of looking at the same data, and
that it's our job to decide which is most appropriate, based on our
knowledge of the data. (Having said that, IIRC there are some genuine
systems out there that do distinguish, in the filesystem, between
text files and binary files. But on most systems, the point stands.)
This is how best to use a crappy language for this purpose.
If, as you claim, you want to invade my turf, burn my huts, and carry
off my women (your words, not mine), you're not going to achieve that
objective by stepping gingerly across the border, putting your hands
over your head, and yelling "this place sucks". You're going to have
to conquer the land, and that means learning all about it.
Stupid code doing a stupid thing
I see crowds of people, walking round in a ring.
In OO languages, you make copy or buy a simple abstraction of
"file" which encapsulates the detection of line breaks. Case
closed.
Likefgets?
Gee you must be using it right as we speak. You lost another blank,
cowboy.
The original <4a75ae52$1@xxxxxxxxxxxxxx> has the space there. Looks
like you made yet another unjustified accusation.
<snip>
There are excellet introductory texts to the language availabe. You
may want to consider reading them.
I'd rather read My Pet Goat.
The problem is that, like you, your pet goat doesn't know C.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
This line unintentionally left unblank
.
- Follow-Ups:
- Re: Code Review - is this code ***
- From: spinoza1111
- Re: Code Review - is this code ***
- References:
- Re: Code Review - is this code ***
- From: pete
- Re: Code Review - is this code ***
- From: spinoza1111
- Re: Code Review - is this code ***
- From: pete
- Re: Code Review - is this code ***
- From: spinoza1111
- Re: Code Review - is this code ***
- From: Dennis
- Re: Code Review - is this code ***
- From: spinoza1111
- Re: Code Review - is this code ***
- Prev by Date: ▣▣▣→www.guomeitrade.com==China Wholesale Various Fashion Brand Watches,Ebel,Bape,D&G,Kappa,Chopard,Prada,Titoni,U-BOAT,Chanel,Hamilton,Oris,Armani,Tudor,LV,Panerai,Panerai,Ferrari,etc..Paypal Payment
- Next by Date: Re: passing variable number of arguments to a function
- Previous by thread: Re: Code Review - is this code ***
- Next by thread: Re: Code Review - is this code ***
- Index(es):