Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Program to create csv file and write into it |
| Date | 2016-12-11 01:19 -0800 |
| Organization | None to speak of |
| Message-ID | <lnk2b6vn5n.fsf@kst-u.example.com> (permalink) |
| References | <6b201709-fae0-4a06-9783-af485e4040bf@googlegroups.com> <a4fc5b02-348c-4876-9e4f-97d20c654d7a@googlegroups.com> <3a3c9153-6813-4eb1-993a-db94b41272ac@googlegroups.com> <a7e939cd-7892-4d5b-ba0a-4c4fec5080e8@googlegroups.com> |
Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On Sunday, December 11, 2016 at 7:57:06 AM UTC, Alla _ wrote:
>> I love this word "just" ) I am sorry, but for me "just write
>> out the header doesn't ring a bell at all. And how can I escape
>> strings, if I have to have names of fields? It seems I also have
>> yet no idea how to write alpha words not in a string variable.
>>
> We have
>
> struct employee
> {
> char *fname;
> char *sname;
> long payrollid;
> float salary;
> }
>
> We want a CSV file that looks like this
>
> First name, Surname, ID, Salary
> "Fred", "Bloggs", 1234567, 32000.00
> "Joe", "Sixpack", 2345678, 29000.00
> "Dilbert", "Smith", 7654321, 45000,00
No, a CSV file normally doesn't have spaces after the commas, unless the
spaces are part of the fields. (And you have a typo on the last line.)
I'd expect that to look like:
First name,Surname,ID,Salary
Fred,Bloggs,1234567,32000.00
Joe,Sixpack,2345678,29000.00
Dilbert,Smith,7654321,45000.00
> You have to know what names you will give the columns.
> Whilst they will bear a relation to the struct field
> names, it's unlikely they will be all identical.
>
> Then the names have to be wrapped in quotes, and the
> salaries formatted so that there are exactly two figures
> after the decimal place.
Why do the names have to be wrapped in quotes? CSV formats require
quotes only for fields that contain special characters, particularly
embedded commas.
Why do the salaries in the CSV file have to have exactly two digits
after the decimal? All that should really matter is that the correct
value is represented.
> It gets harder if commas or other punctuation is allowed
> in names. That's what "escaping the string" means. However
> most databases disallow commas in people's names.
I find that difficult to believe. Is "John Smith, Junior" just out of
luck? A database should make as few assumptions as possible about
people's names. You might want to take a look at this:
https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-10 09:30 -0800
Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 20:42 +0000
Re: Program to create csv file and write into it Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-10 15:56 -0500
Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 21:08 +0000
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-10 23:48 -0800
Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-11 00:01 -0800
Re: Program to create csv file and write into it Keith Thompson <kst-u@mib.org> - 2016-12-11 01:12 -0800
Re: Program to create csv file and write into it Keith Thompson <kst-u@mib.org> - 2016-12-11 01:27 -0800
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-11 04:50 -0800
Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-11 09:42 -0800
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:13 -0800
Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 08:34 +0000
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:50 -0800
Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 09:02 +0000
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 02:52 -0800
Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 10:59 +0000
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 03:23 -0800
Re: Program to create csv file and write into it mx2927 <mx2927@gmail.com> - 2016-12-11 20:44 +0100
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-11 23:57 -0800
Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-12 01:06 -0800
Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 11:39 +0000
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-11 04:47 -0800
Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 14:43 +0000
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:56 -0800
Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-11 09:38 -0800
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:44 -0800
Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 08:48 +0000
Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-12 01:19 -0800
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 02:30 -0800
Re: Program to create csv file and write into it Manfred <noname@invalid.add> - 2016-12-12 15:10 +0100
Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-12 12:35 -0800
Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-10 14:29 -0800
Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-10 23:57 -0800
Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-11 00:33 -0800
Re: Program to create csv file and write into it Keith Thompson <kst-u@mib.org> - 2016-12-11 01:19 -0800
csiph-web