Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Using C to convert excel spreadsheet into mysql Date: Fri, 09 Dec 2016 11:05:34 -0800 Organization: None to speak of Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="2ad4785427d430f26583540ef5e88668"; logging-data="8777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/B4Dqn1Hx9Rzu0iSgtZygt" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:BvJRCtMVFr7wFLsy0X+PvXbFWW8= sha1:JcYbhhT2y77hwbzE5q6ziGFLTxw= Xref: csiph.com comp.lang.c:98598 Richard Heathfield 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 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"