Re: Code Review - is this code ***



On Aug 2, 11:09 pm, "Dennis" <nojunkm...@xxxxxxxxxxxx> wrote:
"spinoza1111" <spinoza1...@xxxxxxxxx> wrote in message

news:290e435e-9892-4245-90c8-ac53dde11d80@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<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? This is C!!

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".

From wikipedia:

"The C Library function fgets() is best avoided in binary mode because
any file not written with the UNIX newline convention [eg. quite a lot
of Windows files] will be seriously misread. Also, in text mode, any
file not written with the system's native newline sequence (such as a
file created on an UNIX system, then copied to a Windows system) will
be misread as well."

Even if it happens to be handled correctly in certain cases, the C
language has NO WAY to properly hide the line separator's value
because THAT would destroy your precious "freedom" to mess everything
up. If I were to use C I would need a discovery routine to check to
see how the file lines are separated using the most general method
available: for example I might want to assume that any character less
than hex 20 (blank) is THE line separator, or that any contiguous runs
of such characters are meant to be line separators (this would handle
both Linux, and old Windows, line breaks as well as other situations).

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.

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.

I sure as hell would not use fgets to get some creep's opinion as to
what constitutes line separation. 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.

This is how best to use a crappy language for this purpose.


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.

<snip>
There are excellet introductory texts to the language availabe. You may want
to consider reading them.

I'd rather read My Pet Goat.

Dennis

.


Loading