Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #98476 > unrolled thread
| Started by | Alla _ <modelling.data@gmail.com> |
|---|---|
| First post | 2016-12-09 02:50 -0800 |
| Last post | 2016-12-11 03:33 -0800 |
| Articles | 20 on this page of 70 — 12 participants |
Back to article view | Back to comp.lang.c
Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 02:50 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 11:13 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 03:50 -0800
Re: Using C to convert excel spreadsheet into mysql Barry Schwarz <schwarzb@dqel.com> - 2016-12-09 08:43 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 09:09 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 07:06 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 15:50 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 09:07 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 17:23 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 09:29 -0800
Re: Using C to convert excel spreadsheet into mysql Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-09 12:43 -0500
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 10:00 -0800
Re: Using C to convert excel spreadsheet into mysql Manfred <noname@invalid.add> - 2016-12-09 19:49 +0100
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 18:15 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 09:55 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 18:22 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 00:23 -0800
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-11 01:33 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 03:38 -0800
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-11 12:35 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-12 01:08 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 10:14 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-12 02:42 -0800
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-12 09:02 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 00:23 -0800
Re: Using C to convert excel spreadsheet into mysql "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-09 13:44 -0500
Re: Using C to convert excel spreadsheet into mysql Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-09 13:57 -0500
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 02:57 -0800
Re: Using C to convert excel spreadsheet into mysql BartC <bc@freeuk.com> - 2016-12-11 11:43 +0000
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 15:51 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 02:42 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 18:09 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 10:15 -0800
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-09 12:16 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 15:56 +0000
Re: Using C to convert excel spreadsheet into mysql luser droog <luser.droog@gmail.com> - 2016-12-11 08:27 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 16:37 +0000
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-11 12:40 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-12 01:13 -0800
Re: Using C to convert excel spreadsheet into mysql Barry Schwarz <schwarzb@dqel.com> - 2016-12-09 08:53 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 09:20 -0800
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-09 11:05 -0800
Re: Using C to convert excel spreadsheet into mysql Manfred <noname@invalid.add> - 2016-12-09 20:27 +0100
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 03:19 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 15:48 +0000
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-11 12:32 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-12 01:16 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 10:31 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-12 02:46 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 10:51 +0000
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-12 09:09 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 03:31 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 14:48 +0000
Using C to convert excel spreadsheet into mysql "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-09 03:16 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 03:50 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 12:00 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 06:47 -0800
Re: Using C to convert excel spreadsheet into mysql "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-09 07:48 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 16:17 +0000
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 08:37 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-09 08:45 -0800
Re: Using C to convert excel spreadsheet into mysql "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-09 08:50 -0800
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 16:55 +0000
Re: Using C to convert excel spreadsheet into mysql "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-09 12:28 -0500
Re: Using C to convert excel spreadsheet into mysql Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 18:10 +0000
Re: Using C to convert excel spreadsheet into mysql "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-12-09 19:48 +0800
Re: Using C to convert excel spreadsheet into mysql Keith Thompson <kst-u@mib.org> - 2016-12-09 11:00 -0800
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 03:03 -0800
Re: Using C to convert excel spreadsheet into mysql andre <ahr@blabla.be> - 2016-12-10 10:43 +0100
Re: Using C to convert excel spreadsheet into mysql Alla _ <modelling.data@gmail.com> - 2016-12-11 03:33 -0800
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-09 09:20 -0800 |
| Message-ID | <16afa4a4-d4a1-4fa0-9425-a25d33bc1d91@googlegroups.com> |
| In reply to | #98566 |
On Friday, December 9, 2016 at 7:53:20 PM UTC+3, Barry Schwarz wrote: > On Fri, 9 Dec 2016 07:06:13 -0800 (PST), Alla _ > <modelling.data@gmail.com> wrote: > > Why are you chopping off attributions? > > ><snip> > >> Step 1: save the Excel spreadsheet data in .csv format. > >> Step 2: LOOK at the saved file. Learn what .csv format is. > > > >Could you, please, do me a huge favour and believe that there is not need to > >continuously add notes like "look at the saved file" - it is an over exaggeration, > >which might useful and suitable for people just learning to think by themselves > >at the age, say, 2 year old ))) > > Look at Richard's step 2 again > > >To make sure I am on the right track (although this is yet not C): I have saved my > >excel test file in csv format simply by Save as in Excel. When I opened it, I didn't see > >any thing different visually - I was expecting something like data, data, data etc, i.e. > >comma separated entries, where commas should have been used instead of excel > >columns. > > If you had done what he suggested, you would realize that your > expectations as expressed here are incomplete. > > >And another question. I have data in the following format: > >years| year1 | year2 | year2 > >item1| numbers| numbers | numbers > > What would your expectation be if item1 contained the text "totals, > first six months only" without the quotation marks? > Yes, lots of "ifs" come up; therefore this project will have numerous assumptions and conditions; I am not capable yet to write the program the way I want and the way it has to be done; so I will need those assumptions ) I intend to write a very simplified version of pro-forma financial statements (maybe only the income statement), and maybe, if I find that the program is not big enough, I will add also at least one valuation model, because it is based on the forecasted income statements. But, once again, I am not intending to copy the Excel functionality, it's not yet possible with my the level of C I have now; my purpose is to write a simple C project using tools I already know, learn them deeper, further learn the thinking process essential in programming (my weakest point), etc. This project choice might not sound line fun, but it is easier for me, then writing some game - I am not a gamer ) > >item2| numbers| numbers | numbers > >etc > > -- > Remove del for email
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-12-09 11:05 -0800 |
| Message-ID | <lnwpf8ylc1.fsf@kst-u.example.com> |
| In reply to | #98477 |
Richard Heathfield <rjh@cpax.org.uk> writes:
> On 09/12/16 10:50, Alla _ wrote:
>> I will be grateful for your help on this matter: I have searched
>> google, and have found numerous suggestions how to convert excel
>> spreadsheet into mysql table with php, but I need to do this using C.
[...]
> You told me not to write the code, so I won't. But I'll give you some hints:
>
> a) you'll get a lot further with fgets and strtok than you will with fscanf.
Yes, but you can't complete the task that way. Code that uses fgets()
in the most straightforward manner will impose a fixed limit on the
length of an input line. That's perfectly reasonable for a first cut at
solving the problem, but eventually you'll want to think about handling
arbitrarily long lines, generated from spreadsheets with arbitrarily
long rows.
strtok() isn't sophisticated enough to handle fields with embedded
commas. For example:
zero,"one_a,one_b",two
contains 3 fields, but strtok() will split it into 4. (There's also
special syntax for fields that contain quotation marks; I don't know
what it is, or even whether there's a consistent accepted standard.)
Ignoring that issue is reasonable for a first draft.
[...]
--
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"
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@invalid.add> |
|---|---|
| Date | 2016-12-09 20:27 +0100 |
| Message-ID | <o2f0j2$1cmq$1@gioia.aioe.org> |
| In reply to | #98598 |
On 12/9/2016 8:05 PM, Keith Thompson wrote: > strtok() isn't sophisticated enough to handle fields with embedded > commas. For example: > > zero,"one_a,one_b",two > > contains 3 fields, but strtok() will split it into 4. (There's also > special syntax for fields that contain quotation marks; I don't know > what it is, or even whether there's a consistent accepted standard.) > Ignoring that issue is reasonable for a first draft. There's at least one more limitation: strtok merges adjacent delimiters, so it won't scan empty fields.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-11 03:19 -0800 |
| Message-ID | <ad1b77d5-fc5d-404b-826b-26f49d10f034@googlegroups.com> |
| In reply to | #98598 |
On Friday, December 9, 2016 at 10:04:47 PM UTC+3, Keith Thompson wrote: > Richard Heathfield <rjh@cpax.org.uk> writes: > > On 09/12/16 10:50, Alla _ wrote: > >> I will be grateful for your help on this matter: I have searched > >> google, and have found numerous suggestions how to convert excel > >> spreadsheet into mysql table with php, but I need to do this using C. > [...] > > You told me not to write the code, so I won't. But I'll give you some hints: > > > > a) you'll get a lot further with fgets and strtok than you will with fscanf. > > Yes, but you can't complete the task that way. Code that uses fgets() > in the most straightforward manner will impose a fixed limit on the > length of an input line. That's perfectly reasonable for a first cut at > solving the problem, but eventually you'll want to think about handling > arbitrarily long lines, generated from spreadsheets with arbitrarily > long rows. > Will it more reasonable to do the following: # use a variable to store the length of the line = potential number of elements x the size of each (i.e. by 1 because those are chars) + '\0' # malloc memory for a line based on that length and potential number of elements # use that length in the fgets to read the line from csv file # check if there is enough memory allocated, compute the length of the final line, and if there is not enough memory reallocate it; or free the memory not in use; (I have done that some time ago, I was provided with the code); it sounds very complicated, but if it is potentially correct, I would like to implement this challenge in this program. What do you think? > strtok() isn't sophisticated enough to handle fields with embedded > commas. For example: > > zero,"one_a,one_b",two > > contains 3 fields, but strtok() will split it into 4. (There's also > special syntax for fields that contain quotation marks; I don't know > what it is, or even whether there's a consistent accepted standard.) > Ignoring that issue is reasonable for a first draft. > > [...] > > -- > 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"
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-11 15:48 +0000 |
| Message-ID | <o2jse1$v2m$1@dont-email.me> |
| In reply to | #98777 |
On 11/12/16 11:19, Alla _ wrote: > On Friday, December 9, 2016 at 10:04:47 PM UTC+3, Keith Thompson wrote: >> Richard Heathfield <rjh@cpax.org.uk> writes: >>> On 09/12/16 10:50, Alla _ wrote: >>>> I will be grateful for your help on this matter: I have searched >>>> google, and have found numerous suggestions how to convert excel >>>> spreadsheet into mysql table with php, but I need to do this using C. >> [...] >>> You told me not to write the code, so I won't. But I'll give you some hints: >>> >>> a) you'll get a lot further with fgets and strtok than you will with fscanf. >> >> Yes, but you can't complete the task that way. Code that uses fgets() >> in the most straightforward manner will impose a fixed limit on the >> length of an input line. That's perfectly reasonable for a first cut at >> solving the problem, but eventually you'll want to think about handling >> arbitrarily long lines, generated from spreadsheets with arbitrarily >> long rows. >> > Will it more reasonable to do the following: Stop and think. What is your goal here? To write a fully robust, generic, commercial-quality program that will be used over and over again in all kinds of environments? Or is it to learn a little more about C? If the latter, I suggest you don't worry about Keith's red herring, and focus instead on learning how to do basic parsing, which is what this exercise seems to be about. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-12-11 12:32 -0800 |
| Message-ID | <lnpokytdeg.fsf@kst-u.example.com> |
| In reply to | #98814 |
Richard Heathfield <rjh@cpax.org.uk> writes:
> On 11/12/16 11:19, Alla _ wrote:
[...]
>> Will it more reasonable to do the following:
>
> Stop and think. What is your goal here? To write a fully robust,
> generic, commercial-quality program that will be used over and over
> again in all kinds of environments? Or is it to learn a little more
> about C? If the latter, I suggest you don't worry about Keith's red
> herring, and focus instead on learning how to do basic parsing, which is
> what this exercise seems to be about.
I agree. Keep the issue in the back of your mind, but for this
exercise I suggest you get something working first, even if it
doesn't handle unreasonably long input lines.
--
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"
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-12 01:16 -0800 |
| Message-ID | <b5008fef-73c0-42f7-837e-20a07b012a07@googlegroups.com> |
| In reply to | #98814 |
On Sunday, December 11, 2016 at 6:48:44 PM UTC+3, Richard Heathfield wrote: > On 11/12/16 11:19, Alla _ wrote: > > On Friday, December 9, 2016 at 10:04:47 PM UTC+3, Keith Thompson wrote: > >> Richard Heathfield <rjh@cpax.org.uk> writes: > >>> On 09/12/16 10:50, Alla _ wrote: > >>>> I will be grateful for your help on this matter: I have searched > >>>> google, and have found numerous suggestions how to convert excel > >>>> spreadsheet into mysql table with php, but I need to do this using C. > >> [...] > >>> You told me not to write the code, so I won't. But I'll give you some hints: > >>> > >>> a) you'll get a lot further with fgets and strtok than you will with fscanf. > >> > >> Yes, but you can't complete the task that way. Code that uses fgets() > >> in the most straightforward manner will impose a fixed limit on the > >> length of an input line. That's perfectly reasonable for a first cut at > >> solving the problem, but eventually you'll want to think about handling > >> arbitrarily long lines, generated from spreadsheets with arbitrarily > >> long rows. > >> > > Will it more reasonable to do the following: > > Stop and think. What is your goal here? To write a fully robust, > generic, commercial-quality program that will be used over and over > again in all kinds of environments? Or is it to learn a little more > about C? If the latter, I suggest you don't worry about Keith's red > herring, and focus instead on learning how to do basic parsing, which is > what this exercise seems to be about. > I won't even dare to think of creating even a tiny commercially applicable program; that's yet out of my capacity ) But I can consider at least the issue with the memory allocation, if it is applicable in my case. > -- > Richard Heathfield > Email: rjh at cpax dot org dot uk > "Usenet is a strange place" - dmr 29 July 1999 > Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-12 10:31 +0000 |
| Message-ID | <o2lu77$tmk$1@dont-email.me> |
| In reply to | #99017 |
On 12/12/16 09:16, Alla _ wrote: <snip> > I won't even dare to think of creating even a tiny commercially applicable > program; Well, quite so. > that's yet out of my capacity ) But I can consider at least the > issue with the memory allocation, if it is applicable in my case. I don't think it is, at least not yet. What you hope to achieve can easily be achieved without it. It's something you need to learn, but you don't need to learn it *yet*. For now, use a fixed-length buffer that's "big enough and to spare". You are very unlikely to need to read a line containing more than a few hundred characters, so just set up an array that's ludicrously big: say, 2048 characters. Then you can get on with your program without worrying about dynamic allocation. We can cover that later on. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-12 02:46 -0800 |
| Message-ID | <53f0521c-2eab-4148-b345-6af3dc37b046@googlegroups.com> |
| In reply to | #99025 |
On Monday, December 12, 2016 at 1:31:28 PM UTC+3, Richard Heathfield wrote: > On 12/12/16 09:16, Alla _ wrote: > > <snip> > > > I won't even dare to think of creating even a tiny commercially applicable > > program; > > Well, quite so. > > > that's yet out of my capacity ) But I can consider at least the > > issue with the memory allocation, if it is applicable in my case. > > I don't think it is, at least not yet. What you hope to achieve can > easily be achieved without it. It's something you need to learn, but you > don't need to learn it *yet*. For now, use a fixed-length buffer that's > "big enough and to spare". You are very unlikely to need to read a line > containing more than a few hundred characters, so just set up an array > that's ludicrously big: say, 2048 characters. Then you can get on with > your program without worrying about dynamic allocation. We can cover > that later on. > > Please ) Do me a favor and comment on that part. I have already done it in one of the programs, and it is very interesting and useful. I promise I won't cross any other reasonable boundaries ) Please )
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-12 10:51 +0000 |
| Message-ID | <o2lvde$1sq$1@dont-email.me> |
| In reply to | #99028 |
On 12/12/16 10:46, Alla _ wrote: > On Monday, December 12, 2016 at 1:31:28 PM UTC+3, Richard Heathfield wrote: >> On 12/12/16 09:16, Alla _ wrote: >> >> <snip> >> >>> I won't even dare to think of creating even a tiny commercially applicable >>> program; >> >> Well, quite so. >> >>> that's yet out of my capacity ) But I can consider at least the >>> issue with the memory allocation, if it is applicable in my case. >> >> I don't think it is, at least not yet. What you hope to achieve can >> easily be achieved without it. It's something you need to learn, but you >> don't need to learn it *yet*. For now, use a fixed-length buffer that's >> "big enough and to spare". You are very unlikely to need to read a line >> containing more than a few hundred characters, so just set up an array >> that's ludicrously big: say, 2048 characters. Then you can get on with >> your program without worrying about dynamic allocation. We can cover >> that later on. >> >> > Please ) Do me a favor and comment on that part. Which part? > I have already done it in one of the programs, What are we talking about here? Dynamic memory allocation? And which program have you done it in? I'm happy to help out if I can, but I can't go clicking around random threads in the hope of picking out the precise article you're talking about. If you're asking about how to read a complete line from a stream without knowing in advance how long it is, then I can show you how to do that. Is that what you want to know? -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-12-12 09:09 -0800 |
| Message-ID | <lny3zlqdk0.fsf@kst-u.example.com> |
| In reply to | #99028 |
Alla _ <modelling.data@gmail.com> writes:
> On Monday, December 12, 2016 at 1:31:28 PM UTC+3, Richard Heathfield wrote:
>> On 12/12/16 09:16, Alla _ wrote:
>>
>> <snip>
>>
>> > I won't even dare to think of creating even a tiny commercially applicable
>> > program;
>>
>> Well, quite so.
>>
>> > that's yet out of my capacity ) But I can consider at least the
>> > issue with the memory allocation, if it is applicable in my case.
>>
>> I don't think it is, at least not yet. What you hope to achieve can
>> easily be achieved without it. It's something you need to learn, but you
>> don't need to learn it *yet*. For now, use a fixed-length buffer that's
>> "big enough and to spare". You are very unlikely to need to read a line
>> containing more than a few hundred characters, so just set up an array
>> that's ludicrously big: say, 2048 characters. Then you can get on with
>> your program without worrying about dynamic allocation. We can cover
>> that later on.
>>
>>
> Please ) Do me a favor and comment on that part. I have already done
> it in one of the programs, and it is very interesting and useful. I promise
> I won't cross any other reasonable boundaries ) Please )
I think what you're asking about is reading and storing arbitrarily long
lines of text, without knowing how long each line is. That can
certainly be a useful thing to do.
My advice (which you're free to ignore) is to do this in a separate
program, at least for now, not as part of the CSV-processing program
you're currently working on. For your CSV-processing program, just use
a fixed width of, say, 2048 characters. Separately, write a function
that reads a variable-length line, allocating as needed (realloc() will
be useful). Once you've got that working reliably (I suggest reviewing
it here), you can drop that function into your CSV-processing program.
Your initial attempt at a line-reading function is bound to be buggy
(that's as true for me as it is for you). You don't want to be tracking
down bugs in your low-level input routine at the same time as you're
working on CSV financial processing.
--
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"
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-11 03:31 -0800 |
| Message-ID | <c5689ca6-9abf-4b6e-8dd4-b97c88270fc9@googlegroups.com> |
| In reply to | #98598 |
On Friday, December 9, 2016 at 10:04:47 PM UTC+3, Keith Thompson wrote:
> Richard Heathfield <rjh@cpax.org.uk> writes:
> > On 09/12/16 10:50, Alla _ wrote:
> >> I will be grateful for your help on this matter: I have searched
> >> google, and have found numerous suggestions how to convert excel
> >> spreadsheet into mysql table with php, but I need to do this using C.
> [...]
> > You told me not to write the code, so I won't. But I'll give you some hints:
> >
> > a) you'll get a lot further with fgets and strtok than you will with fscanf.
>
> Yes, but you can't complete the task that way. Code that uses fgets()
> in the most straightforward manner will impose a fixed limit on the
> length of an input line. That's perfectly reasonable for a first cut at
> solving the problem, but eventually you'll want to think about handling
> arbitrarily long lines, generated from spreadsheets with arbitrarily
> long rows.
>
> strtok() isn't sophisticated enough to handle fields with embedded
> commas. For example:
>
> zero,"one_a,one_b",two
>
> contains 3 fields, but strtok() will split it into 4. (There's also
> special syntax for fields that contain quotation marks; I don't know
> what it is, or even whether there's a consistent accepted standard.)
> Ignoring that issue is reasonable for a first draft.
>
I think I don't need functions from a library to split the given array
(line that I will get from gets) into its separate elements. Please,
correct me if I am wrong, I assume I can use nested for loop
and certain conditions and/or ifs to store each field of that line
into separate arrays, then convert the ones that are supposed
to be digits into integers, and store all of those in a struct.
Thus I think I can get a set of structures, each of which
will represent the row from a file. For example:
row 1
Income Statement,2011,2012,2013,2014,2015
struct finstatement
{
char row_name [] = "Income Statement";
unsigned int col_values[] = {2011,2012,2013,2014,2015};
}
Same of all other lines.
Before proceeding any further, I need to finish writing
my pseudo code, because I am don't know yet how I will be able
to use column values from this first row to parse corresponding
numbers from all other rows, the way they are generated in
the original excel file.
<snip>
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-11 14:48 +0000 |
| Message-ID | <o2jot2$ffe$1@dont-email.me> |
| In reply to | #98598 |
On 09/12/16 19:05, Keith Thompson wrote: > Richard Heathfield <rjh@cpax.org.uk> writes: >> On 09/12/16 10:50, Alla _ wrote: >>> I will be grateful for your help on this matter: I have searched >>> google, and have found numerous suggestions how to convert excel >>> spreadsheet into mysql table with php, but I need to do this using C. > [...] >> You told me not to write the code, so I won't. But I'll give you some hints: >> >> a) you'll get a lot further with fgets and strtok than you will with fscanf. > > Yes, but you can't complete the task that way. That depends on the task. If we're talking about doing the accounts for a major multi-national corporation, I agree. If we're talking about a student exercise, then it depends on the exercise. > Code that uses fgets() > in the most straightforward manner will impose a fixed limit on the > length of an input line. Yes, that's right. Think of the student. This is not the time for a completely general production-quality solution. > That's perfectly reasonable for a first cut at > solving the problem, I agree entirely. > but eventually you'll want to think about handling > arbitrarily long lines, generated from spreadsheets with arbitrarily > long rows. Yes, but "eventually" need not be "now". Construction of the capital of the whole of the civilised ancient world was not completed within a single 24-hour period. > strtok() isn't sophisticated enough to handle fields with embedded > commas. Again, I agree. And in fact we've seen that the OP's input file will included embedded commas, so a better way will need to be found. (This isn't difficult.) -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2016-12-09 03:16 -0800 |
| Message-ID | <9f5bdee8-404f-47ca-8a26-286ceb49ff44@googlegroups.com> |
| In reply to | #98476 |
Save it as CSV file, and then parse it. Microsoft exposes "Excel.Application" as an object you can instantiate in C++. You can then obtain interfaces to the various functions, but it is really complex to get everything just right. If you want to do it, search for "Excel automation in C" and you might find some hits. Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online automation examples there. Best regards, Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-09 03:50 -0800 |
| Message-ID | <3c8fcff6-bc4f-4454-a016-3ef4df31ab75@googlegroups.com> |
| In reply to | #98478 |
On Friday, December 9, 2016 at 2:17:04 PM UTC+3, Rick C. Hodgin wrote: > Save it as CSV file, and then parse it. > > Microsoft exposes "Excel.Application" as an object you can instantiate > in C++. You can then obtain interfaces to the various functions, but > it is really complex to get everything just right. > > If you want to do it, search for "Excel automation in C" and you > might find some hits. > > Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online > automation examples there. > Thank you!
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-09 12:00 +0000 |
| Message-ID | <o2e69q$8iq$1@dont-email.me> |
| In reply to | #98482 |
[Before I could respond to this message, I considered it necessary to remove my newsreader's filter on Rick C Hodgin, to give him the opportunity to respond to the following, should he so choose.] On 09/12/16 11:50, Alla _ wrote: > On Friday, December 9, 2016 at 2:17:04 PM UTC+3, Rick C. Hodgin wrote: >> Save it as CSV file, and then parse it. So far so good. >> Microsoft exposes "Excel.Application" as an object you can instantiate >> in C++. You can then obtain interfaces to the various functions, but >> it is really complex to get everything just right. This is really bad advice. Alla is trying to learn C, not Excel or Visual C++. From what I can gather, the whole point of this exercise is to give Alla experience in C programming. Excel automation and Visual C++ libraries are, therefore, completely the wrong way to go. >> If you want to do it, search for "Excel automation in C" and you >> might find some hits. >> >> Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online >> automation examples there. And how, precisely, will that help Alla to learn more about C? > Thank you! Alla, that's a very polite response to a very ignorant "contribution". I commend you on your restraint. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-09 06:47 -0800 |
| Message-ID | <bf002858-1827-4ce3-b1ed-7671b5ec9638@googlegroups.com> |
| In reply to | #98483 |
On Friday, December 9, 2016 at 3:00:18 PM UTC+3, Richard Heathfield wrote: > [Before I could respond to this message, I considered it necessary to > remove my newsreader's filter on Rick C Hodgin, to give him the > opportunity to respond to the following, should he so choose.] > > On 09/12/16 11:50, Alla _ wrote: > > On Friday, December 9, 2016 at 2:17:04 PM UTC+3, Rick C. Hodgin wrote: > >> Save it as CSV file, and then parse it. > > So far so good. > > >> Microsoft exposes "Excel.Application" as an object you can instantiate > >> in C++. You can then obtain interfaces to the various functions, but > >> it is really complex to get everything just right. > > This is really bad advice. Alla is trying to learn C, not Excel or > Visual C++. From what I can gather, the whole point of this exercise is > to give Alla experience in C programming. Yes, exactly. It's the only reason I making my life much harder that it could have been ) Excel automation and Visual > C++ libraries are, therefore, completely the wrong way to go. > > >> If you want to do it, search for "Excel automation in C" and you > >> might find some hits. > >> > >> Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online > >> automation examples there. > > And how, precisely, will that help Alla to learn more about C? > > > Thank you! > > Alla, that's a very polite response to a very ignorant "contribution". I > commend you on your restraint. > > -- > Richard Heathfield > Email: rjh at cpax dot org dot uk > "Usenet is a strange place" - dmr 29 July 1999 > Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2016-12-09 07:48 -0800 |
| Message-ID | <6c5dfb4c-892f-471a-b39a-602a7ee793fc@googlegroups.com> |
| In reply to | #98483 |
On Friday, December 9, 2016 at 7:00:18 AM UTC-5, Richard Heathfield wrote:
> [Before I could respond to this message, I considered it necessary to
> remove my newsreader's filter on Rick C Hodgin, to give him the
> opportunity to respond to the following, should he so choose.]
>
> On 09/12/16 11:50, Alla _ wrote:
> > On Friday, December 9, 2016 at 2:17:04 PM UTC+3, Rick C. Hodgin wrote:
> >> Save it as CSV file, and then parse it.
>
> So far so good.
>
> >> Microsoft exposes "Excel.Application" as an object you can instantiate
> >> in C++. You can then obtain interfaces to the various functions, but
> >> it is really complex to get everything just right.
>
> This is really bad advice. Alla is trying to learn C, not Excel or
> Visual C++. From what I can gather, the whole point of this exercise is
> to give Alla experience in C programming. Excel automation and Visual
> C++ libraries are, therefore, completely the wrong way to go.
>
> >> If you want to do it, search for "Excel automation in C" and you
> >> might find some hits.
> >>
> >> Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online
> >> automation examples there.
>
> And how, precisely, will that help Alla to learn more about C?
>
> > Thank you!
>
> Alla, that's a very polite response to a very ignorant "contribution". I
> commend you on your restraint.
Alla, it was not my intention to mislead you or cause you confusion.
I would like to suggest that if you need to do this in C, it might
be worth creating a Visual Basic DLL which you can call from C to
retrieve the information for you as you need it, as VB also allows
very easy access to the Excel.application object and all of Excel's
internal content. You can create a small DLL that you use in C to
call simple functions like:
open_spreadsheet()
get_cell_type()
get_cell_character_data()
get_cell_integer_data()
get_cell_floating_point_data()
get_cell_date_data()
close_spreadsheet()
et cetera
By using this interface, you can still access and process your data
from C, but you will be using the higher level mechanisms to access
it directly from the raw spreadsheet, rather than through conversion
to CSV.
You can also update Excel spreadsheets that way:
set_cell_character_data()
set_cell_interger_data()
et cetera
...and use it to compute values by populating cells with data and
retrieving post-compute results, etc.
-----
If you're interested in doing this let me know. If not, then please
accept my sincerest apologies for wasting your time with my very
ignorant "contribution."
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-09 16:17 +0000 |
| Message-ID | <o2elcc$p7$1@dont-email.me> |
| In reply to | #98534 |
On 09/12/16 15:48, Rick C. Hodgin wrote: > On Friday, December 9, 2016 at 7:00:18 AM UTC-5, Richard Heathfield wrote: >> [Before I could respond to this message, I considered it necessary to >> remove my newsreader's filter on Rick C Hodgin, to give him the >> opportunity to respond to the following, should he so choose.] >> >> On 09/12/16 11:50, Alla _ wrote: >>> On Friday, December 9, 2016 at 2:17:04 PM UTC+3, Rick C. Hodgin wrote: >>>> Save it as CSV file, and then parse it. >> >> So far so good. >> >>>> Microsoft exposes "Excel.Application" as an object you can instantiate >>>> in C++. You can then obtain interfaces to the various functions, but >>>> it is really complex to get everything just right. >> >> This is really bad advice. Alla is trying to learn C, not Excel or >> Visual C++. From what I can gather, the whole point of this exercise is >> to give Alla experience in C programming. Excel automation and Visual >> C++ libraries are, therefore, completely the wrong way to go. >> >>>> If you want to do it, search for "Excel automation in C" and you >>>> might find some hits. >>>> >>>> Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online >>>> automation examples there. >> >> And how, precisely, will that help Alla to learn more about C? >> >>> Thank you! >> >> Alla, that's a very polite response to a very ignorant "contribution". I >> commend you on your restraint. > > Alla, it was not my intention to mislead you or cause you confusion. > > I would like to suggest that if you need to do this in C, That's the point of the exercise, yes. > it might > be worth creating a Visual Basic DLL which you can call from C to > retrieve the information for you as you need it, And how will writing a VB DLL help her to learn C? The *whole point* of the exercise is for him to learn how to do this in C. Not Excel, not Visual C++, not Visual Basic, but C. And she's asked about it not in a Microsoft programming newsgroup but a C newsgroup. What she stands to gain from doing the whole exercise in C is: 1) an understanding of the CSV format; 2) experience in writing C code to parse simple formatted strings; 3) an opportunity to learn more about how functional decomposition can make programs easier to write; 4) the possibility of coming away from this with a handy little library of CSV-parsing tools; 5) not having to work out how to get Visual Studio or Visual Basic to work on her Mac. <more verbiage snipped> -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-09 08:37 -0800 |
| Message-ID | <caf80c82-bc70-43f1-a318-283b422945d5@googlegroups.com> |
| In reply to | #98534 |
On Friday, December 9, 2016 at 6:48:17 PM UTC+3, Rick C. Hodgin wrote: > On Friday, December 9, 2016 at 7:00:18 AM UTC-5, Richard Heathfield wrote: > > [Before I could respond to this message, I considered it necessary to > > remove my newsreader's filter on Rick C Hodgin, to give him the > > opportunity to respond to the following, should he so choose.] > > > > On 09/12/16 11:50, Alla _ wrote: > > > On Friday, December 9, 2016 at 2:17:04 PM UTC+3, Rick C. Hodgin wrote: > > >> Save it as CSV file, and then parse it. > > > > So far so good. > > > > >> Microsoft exposes "Excel.Application" as an object you can instantiate > > >> in C++. You can then obtain interfaces to the various functions, but > > >> it is really complex to get everything just right. > > > > This is really bad advice. Alla is trying to learn C, not Excel or > > Visual C++. From what I can gather, the whole point of this exercise is > > to give Alla experience in C programming. Excel automation and Visual > > C++ libraries are, therefore, completely the wrong way to go. > > > > >> If you want to do it, search for "Excel automation in C" and you > > >> might find some hits. > > >> > > >> Much easier to do it in Visual Basic or Visual FoxPro. Plenty of online > > >> automation examples there. > > > > And how, precisely, will that help Alla to learn more about C? > > > > > Thank you! > > > > Alla, that's a very polite response to a very ignorant "contribution". I > > commend you on your restraint. > > Alla, it was not my intention to mislead you or cause you confusion. Please, do not worry, I know that you only wanted to help. And I save your advice in case I need to use this approach in the future, without C. > > I would like to suggest that if you need to do this in C, it might > be worth creating a Visual Basic DLL which you can call from C to > retrieve the information for you as you need it, as VB also allows > very easy access to the Excel.application object and all of Excel's > internal content. You can create a small DLL that you use in C to > call simple functions like: > > open_spreadsheet() > get_cell_type() > get_cell_character_data() > get_cell_integer_data() > get_cell_floating_point_data() > get_cell_date_data() > close_spreadsheet() > et cetera > > By using this interface, you can still access and process your data > from C, but you will be using the higher level mechanisms to access > it directly from the raw spreadsheet, rather than through conversion > to CSV. > > You can also update Excel spreadsheets that way: > > set_cell_character_data() > set_cell_interger_data() > et cetera > > ...and use it to compute values by populating cells with data and > retrieving post-compute results, etc. > > ----- > If you're interested in doing this let me know. If not, then please > accept my sincerest apologies for wasting your time with my very > ignorant "contribution." > > Best regards, > Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
Back to top | Article view | comp.lang.c
csiph-web