🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2292

Re: quotes in sscanf() ????????????

#2292
From: Evan Marshall Manning
Date: Fri, 15 Mar 1996 03:15
47 lines
2895 bytes
duling@niehs.nih.gov (Dave Duling) writes:


>Hi.  I need to read in ASCII files of the for:

>#.##,"string with , commas and spaces ", etc....

>so the delimiter is a comma, the string is bound by quotes and contains both 
>commas and spaces (but no other quotes).  So I've played around endlessly with
>this but have not found the answer.  I could write a special function but it 
>would be more eloquent with a standard IO call to sscanf()....

>Thanks for any help, Dave Duling@niehs.nih.gov

You're gonna need something along the lines of:
  fscanf(fp, "%[^,],\"%[^\"]\", etc....", f1, f2...
Where:
             "                    - start of format string
              %[  ]               - string format specified as set of
                                    characters
                ^                 - anthing except
                 ,                - a comma
              %[^,]               - all characters up to but not
                                    including the first comma
                   ,              - match (and discard) that comma
                    \"            - match & discard a quote (escaped so
                                    it doesn't terminate the format
                                    string)
                      %[^\"]      - all characters up to but not
                                    including the first quote (escaped so
                                    it doesn't terminate the format
                                    string)
                            \"    - match & discard a quote (escaped so
                                    it doesn't terminate the format
                                    string)
                              ,   - match & discard another comma

Of course all this assumes you know that certain fields are always
quoted.  Otherwise you won't be able to do it with fscanf().

-- 
<<<<< sig copyright Evan M. Manning ======= manning@alumni.caltech.edu >>>>>
#######   Dynamine: A very different minesweeper game for Windows!   #######
#######      <ftp://alumni.caltech.edu/pub/manning/dmine101.zip>     #######
Your eyes are weary from staring at the CRT.  You feel sleepy.  Notice how
restful it is to watch the cursor blink.  Close your eyes.  The opinions
stated above are yours.  You cannot imagine why you ever felt otherwise.
Technical Details
Message-ID: <4ianca$h98@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4i8036$46d@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: manning@alumnae.caltech.edu (Evan Marshall Manning)
Newsgroups: comp.lang.c.moderated
Subject: Re: quotes in sscanf() ????????????
Date: 14 Mar 1996 21:15:22 -0600
Organization: California Institute of Technology, Pasadena
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4ianca$h98@solutions.solon.com>
References: <4i8036$46d@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: NN version 6.5.0 #10 (NOV)