Question regarding fgets and new lines

K

Keith Thompson

Eric Sosman said:
Keith Thompson wrote: [...]
Well, you *could* return as many unique error conditions as you like
with a simple char* return value:
const char *const gl_EOF = "getline: EOF";
const char *const gl_io_error = "getline: I/O error";
const char *const gl_malloc_failed = "getline: malloc failed";
...
[...]
Different people design different interfaces for the same
task! Different people decompose the same task in different ways!
Ultimately, it comes down to what might be called "taste" (there's
just no point in arguing with Gus), or to put it on a more respectable
footing it comes down to a guess about the likely usage scenarios for
the new facility. There might (or might not) be the germ of a thesis
topic for someone who wants to make a study of how different
programmers approach similar problems: were you corrupted by an early
exposure to
Forth, was your mother frightened by a COBOL compiler?
[...]

Thinking about it a bit more, I don't necessarily *like* the interface
I came up with. If you really really want to have your function
return just a single char* value and still be able to represent
multiple error conditions, what I suggested is probably close to the
best way to do it. The language provides one distinguished pointer
value that doesn't point to actual data; gl_EOF, gl_io_error, et al
can be thought of as multiple null pointers. But returning the actual
data and a status code separately is, IMHO, better style.

It would be nice if a function could return multiple values, so you
could do something like:

char *line;
int status;
(line, status) = getline(stdin);

But that's not C. Yes, getline() could return a struct (and using a
struct might not be a horrible idea), but using a struct probably
isn't as convenient as multiple return values would be.
 
M

Malcolm

Bill Reid said:
Chris Torek said:
[much snippage]
... but CSV files are not "line oriented"

...you may be thinking of a "CSV" file format that co-opted the
name ...

So, you are talking about CSV files, and he is talking about CSV
files, which are completely different things?

"Not Claw, Claw!"

Exactly!

He's most certainly talking about just randomly exporting nonsense
from his weird Uncle Billy's "Excel" program as a *.csv file, such as:

123.45,678.9,135.45,"Hi there
this is a new line","Hi again sucker",680.24
791.23,579.35,,,,

Note carefully, however, that like all "CSV" files since the dawn
of man trying to portably export data by studiously avoiding binary
formats, it IS actually "line-oriented"; there were two rows of a
maximum of six columns each in the Excel file. The only reason it
"exported" as three lines was because of the "embedded newline" in
the cell at the fourth column of the first row; other than that, it
follows
the grand tradition of a "field" being delimited by a comma (or
whatever) and the "record" being delimited by a newline.

If I wanted to, I guess I could have inserted the complete text for
"War and Peace" into that column, and thus over-flowed my
512-character buffer by a factor of about a million. For that
matter, I could have inserted the complete text for "Paradise
Lost" in the cell at the first column of the second row, even though
I put a float number in that column in the first row, and what the hell
would I do to "process" THAT data? I don't even think a
"state machine" would save my bacon at that point...

I will leave those problems to people oh so much smarter than I.
I will just continue to humbly bumble through "CSV" files that list
crap like the average home price for the last 30 years for the
top 40 metropolitan areas in the USA, and pray to God some
joker didn't insert the text for the "Kama Sutra" in the column for "1999"
at the row for "Miami/Dade County, FLA"...
These days, we have huge amounts of memory avialable and so we can afford to
throw it away in making our functions easy to use.
If you go onto my website and look under the "Fuzzy Logic Trees" section you
will find a file called csv.c which is a general-purpose csv file loader.
You only need to have one such function, and then you can quite happily
handle "War and Peace" in a field.
 
B

Bill Reid

Robert Gamble said:
Bill said:
Chris Torek said:
[much snippage]

... but CSV files are not "line oriented"

...you may be thinking of a "CSV" file format that co-opted the
name ...

So, you are talking about CSV files, and he is talking about CSV
files, which are completely different things?

"Not Claw, Claw!"

Exactly!

He's most certainly talking about just randomly exporting nonsense
from his weird Uncle Billy's "Excel" program as a *.csv file, such as:

123.45,678.9,135.45,"Hi there
this is a new line","Hi again sucker",680.24
791.23,579.35,,,,

Note carefully, however, that like all "CSV" files since the dawn
of man trying to portably export data by studiously avoiding binary
formats, it IS actually "line-oriented";

Nonsense, CSV is a binary format and always has been.

!!!!

Whaaaa...?!?!!

A "binary" format!???!! You call my example that I "exported"
from Excel a "binary" format? My world is askew! Also, you've
probably just given our weird Uncle Billy a heart attack...thanks
for that...
You cannot
properly parse a CSV file by assuming that each line is its own record.


I am not aware of this grand tradition

Well, I'm nothing if not a traditionalist...
you speak of and I have
processed numerous CSV files from multiple sources and applications
over the last few years, all of which handled embedded commas and
newlines. You may be confusing CSV with comma-delimited files,

"CDV" files? I must again say, "Whaaaa?!??!!"
a text
format in which all commas are row separators, records are delimited
with newlines, and commas and newlines cannot exist in the actual data.

Yeah, just like the "*.csv" file I "exported" from Excel: a text format,
the end of every "record" is delimited by a newline, and surprise,
commas COULD always exist in a "CSV" file, just within a text
"field" protected by enclosing double quotes, which was always
part of the "classic" CSV format; after you've "protected" your
text fields, an "embedded newline" ain't hardly nuttin'...
Comma-delimited files are significantly easier to process than real
CSV files but suffer from obvious disadvantages that are shared with
any character-delimited format.
Yeah, being able to share data simply across dozens of systems is
quite the disadvantage...
Check out http://en.wikipedia.org/wiki/Comma-separated_values and
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm for the details of
the CSV format and how it is used by real-world applications.
Yeah, probably not going there, don't care...I did admit that I was aware
of a format called "CSV" (is this the "RFC 4180" referenced elsethread?)
that bore little resemblance to the jillions of "CSV" files I've worked
with,
so what?
It's not an overly simple task but it can be done without extraordinary
effort.

Of course it can be done, but if you have no interest in data of that
format, what's the point? Of course, you don't really get the point,
even though I've made it about a billion times: I DON"T CARE ABOUT
PERFORMING SOME TYPE OF RANDOM READING OF
ANY POSSIBLE "CSV" FILE THAT MAY EXIST, I ACTUALLY
WRITE THESE THINGS CALLED "APPLICATIONS" THAT
DO THIS FUNNY THING CALLED "PROCESS DATA".

But everybody has their own hobby...mine is NOT storing the text
of all the great classics of literature as "cells" of an Excel file,
"exporting"
them as a "CSV" file, then "reading" them out of the "CSV" file...
Excel does it,

If you're talking about what I posted as an example of what
Excel "exports" as a "*.csv" file, I have no idea why you would
call that a "binary" file. Apparently, in addition to nobody knowing
exactly what a "CSV" file is, nobody knows what a "binary" file
is either...it just gets worse and worse...
and I have written a real CSV parser in pure
ANSI C which I recently made available at
http://sourceforge.net/projects/libcsv.
Well, good for you, another link that I'll never visit...unless I want
to "import" data that was previously "exported" from Excel (begging
the question why I would want to do that to do something that
isn't covered by Excel functionality in the first place).
 
U

U S Contractors Offering Service A Non-profit

" They say why buy the cOw when the milk is fOr frEE " Inbox
Craig Somerford
to me, natural-video-., skit, Craig, Fast, B-eing-I-nstru., Tell,
Beijing, Ed, Bruno, A, Brandon.Evans, Thank, Please
More options 8:17 pm (0 minutes ago)
29 nov 2006
--http://mail.google.com/mail/?disp=imgs&view=att&th=10f366d5eb0b96e3
24 oct 2006
Thank You
Sincerely:
Craig Oral Somerford



" Working in Faith "
" They say why buy the cOw when the milk is fOr frEE " Inbox
Craig Somerford
to Big, com, newsgator, Cnet, johns, jbullard, AA, Google, alwaysopen,
amsmallbusiness, Awareness, William, Thank, SoHo, Le, Bruno, City,
sbreland, me, Craig, (bcc:Discovery), (bcc:Donald), (bcc:Google),
(bcc:Did), (bcc:donotreply), (bcc:Richard)
More options 8:14 pm (0 minutes ago)

Title: " They say why buy the cOw when...
When: Wed Nov 29 8pm - 9pm (1 hr) (EST)
Where: On your Computer diP shit... "CLICK" tO sEE (map)
Who: (e-mail address removed), (e-mail address removed),
(e-mail address removed), (e-mail address removed)...
more details »
Going? Yes - No - Maybe
Your Agenda for Wed Nov 29, 2006
Prev day (e-mail address removed)
Prev day Di WHERE WERE YOU when she Died (map)
Prev day (e-mail address removed)
Prev day " Chasing cOw to Music Fest "
Prev day York City on Madison ave the day aft...
Prev day " Chasing cOw to Music Fest "
All day " take two encase you loose one ...
All day Welcome to 2Barter.net
All day " Starting a new NeWs PRoGrAme ...
All day " It's not as big of a STEP as o...
All day Don't forget to DOWNLOAD tO gO
All day Kicking paparazzi aSs and loving it
7:30am Gearing uP to gO GoOOOOOOling tOnight...
8:30am Surfing lessons coming soon...
12pm " Grand Opening of this Blessed ...
5:30pm " Grand Opening of 2Barter "
8pm " They say why buy the cOw when...
No later events
view my calendar »
TAKE A TOUR of my nice aSs Mouse House this Christmas tO sEE
"CLICK"
http://www.apple.com/retail/fifthavenue/gallery/vr2.html

Marry Christmas and have a gOO aSs new Year from all of us to you...
www.google.com www.apple.com www.adobe.com www.cingular.com
www.firefox.com
www.mac.com and www.worldofdisney.com plus me www.2Barter.net

Howard Stern "Big ass gold Fish" <[email protected]>
http://www.sirius.com/servlet/ContentServer?pagename=Sirius/Page&c=FlexContent&cid=1130574541451
http://2Barter.net/pics.html

Thank yOu Howard Stern for yOur Barter with 2Barter
"CLICKING" gOOd aSs stUff fuNNy tO
http://video.google.com/videopurchases?hl=en
"CKICK"
http://www.oscar.com/ http://www.heydevils.com/Einstein.mp3

" They say why buy the cOw when the milk is fOr frEE "


--http://www.tis-gdv.de/tis_e/foto/2006/2006_01_x1.htm
http://www.google.com/mail/help/landing.html
http://2barter.net/2barter.net Broadband.wmv
24 oct 2006
Thank You
Sincerely:
http://shop.sirius.com/
http://www.sirius.com/3forfree

"CLICK"
http://www.sirius.com/servlet/ContentServer?pagename=Sirius/CachedPage&c=Channel&cid=1115038982636

"CKICK"
http://shop.sirius.com/edealinv/servlet/ExecMacro?nurl=control/CampaignHome.vm&ctl_nbr=2640&jump4=Y

" Working in Faith "

All in twenty minuets are so sO make sure yOu tell your friends this
Non-profit is ready tO tike some aSs yeP yeP

wE Be Chasing cOw sOOn best bE sure oF that ? While Playing to ?
http://video.google.com/videoplay?docid=-3842734325802545826&q=your+tub
I say I say real suRe of that shit dont tell of me much longer...
And i will give away all your shit...
YeP YeP

"CLICKING" downloads to go eW Be GoOOOOOOling Benefits tO "Check us out
"
http://mail.google.com/mail/help/benefits.html
http://mail.google.com/support/bin/static.py?page=switchguide.html&switch=1

"CLICK" Take a lOOk at my nice aSs Mouse House
http://www.apple.com/ipod/features.html
http://www.spymac.com/upload/news/2006/08/15/m5053_apple_full.jpg
http://www.apple.com/ipodshuffle/

Now i live you with a FuNNy aSs story
"CLICK"
http://groups-beta.google.com/group/skit-kittie-cat-skit


Bill said:
[much snippage]
... but CSV files are not "line oriented"
...you may be thinking of a "CSV" file format that co-opted the
name ...
So, you are talking about CSV files, and he is talking about CSV
files, which are completely different things?
"Not Claw, Claw!"
Exactly!
He's most certainly talking about just randomly exporting nonsense
from his weird Uncle Billy's "Excel" program as a *.csv file, such as:
123.45,678.9,135.45,"Hi there
this is a new line","Hi again sucker",680.24
791.23,579.35,,,,
Note carefully, however, that like all "CSV" files since the dawn
of man trying to portably export data by studiously avoiding binary
formats, it IS actually "line-oriented";
Nonsense, CSV is a binary format and always has been.!!!!

Whaaaa...?!?!!

A "binary" format!???!! You call my example that I "exported"
from Excel a "binary" format? My world is askew! Also, you've
probably just given our weird Uncle Billy a heart attack...thanks
for that...
You cannot
properly parse a CSV file by assuming that each line is its own record.<big sigh>Unless of course, each line in the "CSV" file IS its own record...
I am not aware of this grand traditionWell, I'm nothing if not a traditionalist...
you speak of and I have
processed numerous CSV files from multiple sources and applications
over the last few years, all of which handled embedded commas and
newlines. You may be confusing CSV with comma-delimited files,"CDV" files? I must again say, "Whaaaa?!??!!"
a text
format in which all commas are row separators, records are delimited
with newlines, and commas and newlines cannot exist in the actual data.Yeah, just like the "*.csv" file I "exported" from Excel: a text format,
the end of every "record" is delimited by a newline, and surprise,
commas COULD always exist in a "CSV" file, just within a text
"field" protected by enclosing double quotes, which was always
part of the "classic" CSV format; after you've "protected" your
text fields, an "embedded newline" ain't hardly nuttin'...
Comma-delimited files are significantly easier to process than real
CSV files but suffer from obvious disadvantages that are shared with
any character-delimited format.Yeah, being able to share data simply across dozens of systems is
quite the disadvantage...
Check outhttp://en.wikipedia.org/wiki/Comma-separated_valuesand
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htmfor the details of
the CSV format and how it is used by real-world applications.Yeah, probably not going there, don't care...I did admit that I was aware
of a format called "CSV" (is this the "RFC 4180" referenced elsethread?)
that bore little resemblance to the jillions of "CSV" files I've worked
with,
so what?
It's not an overly simple task but it can be done without extraordinary
effort.Of course it can be done, but if you have no interest in data of that
format, what's the point? Of course, you don't really get the point,
even though I've made it about a billion times: I DON"T CARE ABOUT
PERFORMING SOME TYPE OF RANDOM READING OF
ANY POSSIBLE "CSV" FILE THAT MAY EXIST, I ACTUALLY
WRITE THESE THINGS CALLED "APPLICATIONS" THAT
DO THIS FUNNY THING CALLED "PROCESS DATA".

But everybody has their own hobby...mine is NOT storing the text
of all the great classics of literature as "cells" of an Excel file,
"exporting"
them as a "CSV" file, then "reading" them out of the "CSV" file...
Excel does it,If you're talking about what I posted as an example of what
Excel "exports" as a "*.csv" file, I have no idea why you would
call that a "binary" file. Apparently, in addition to nobody knowing
exactly what a "CSV" file is, nobody knows what a "binary" file
is either...it just gets worse and worse...
and I have written a real CSV parser in pure
ANSI C which I recently made available at
http://sourceforge.net/projects/libcsv.Well, good for you, another link that I'll never visit...unless I want
to "import" data that was previously "exported" from Excel (begging
the question why I would want to do that to do something that
isn't covered by Excel functionality in the first place).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top