<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: fscanf is broken? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793099#M720506</link>
    <description>Mary:&lt;BR /&gt;&lt;BR /&gt;You need to man scanf and look for the %[ section. The problem is thatr %s stops ate the first whitespace; it knows nothing about your quotes. Since you mentioned that the data is being pre-massaged by awk I would throw the quotes away and choose a better field delimter than a space character. My typical choice is a &lt;TAB&gt;.&lt;BR /&gt;&lt;BR /&gt;Your data should then look like this:&lt;BR /&gt;412-99-3412&lt;TAB&gt;08/01/2002&lt;TAB&gt;5.75&lt;TAB&gt;Mary Rice&lt;TAB&gt;Pencils and Paper&lt;LF&gt;&lt;BR /&gt;&lt;BR /&gt;Now change your fscanf to look like this:&lt;BR /&gt;n = fscanf(infile,"%s\t%s\t%lf\t%[^\t\n]\t%[^\t\r\n",account_no,date,&amp;amp;amount,name,description); &lt;BR /&gt;&lt;BR /&gt;Note the %[^\t\n] that means keep scanning until you see a TAB or LF and load the string with that pattern. I left the earlier fields as %s because they seem to not have whitespace.&lt;BR /&gt;&lt;BR /&gt;That should fix you, Clay&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/LF&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;</description>
    <pubDate>Fri, 23 Aug 2002 19:18:55 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2002-08-23T19:18:55Z</dc:date>
    <item>
      <title>fscanf is broken?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793098#M720505</link>
      <description>Hello Experts,&lt;BR /&gt;&lt;BR /&gt;I'm having a problem with fscanf in a program written in ESQL/C. It reads data which has been formatted by an awk program for input into an Informix database.&lt;BR /&gt;&lt;BR /&gt;Each line of data looks like this:&lt;BR /&gt;Account Number Date Amount Name Description&lt;BR /&gt;412-99-3412 08/01/2002 5.75 "Mary Rice" "Pencils and Paper"&lt;BR /&gt;541-45-8911 08/02/2002 121.90 "Robert Rice" "Copier Toner"&lt;BR /&gt;&lt;BR /&gt;I am using an fscanf function like this&lt;BR /&gt;&lt;BR /&gt;n = fscanf(infile,"%s %s %lf %s %s\n",account_no,date,&amp;amp;amount,name,description);&lt;BR /&gt;&lt;BR /&gt;All the variable types are correct. The first three variables work perfectly but Name = ""Robert" and Description = "Rice"".  What am i doing wrong?&lt;BR /&gt;&lt;BR /&gt;Please don't ask to man scanf; I've done that!!!&lt;BR /&gt;&lt;BR /&gt;Thanks for your help,&lt;BR /&gt;Mary</description>
      <pubDate>Fri, 23 Aug 2002 19:10:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793098#M720505</guid>
      <dc:creator>Mary Rice</dc:creator>
      <dc:date>2002-08-23T19:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: fscanf is broken?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793099#M720506</link>
      <description>Mary:&lt;BR /&gt;&lt;BR /&gt;You need to man scanf and look for the %[ section. The problem is thatr %s stops ate the first whitespace; it knows nothing about your quotes. Since you mentioned that the data is being pre-massaged by awk I would throw the quotes away and choose a better field delimter than a space character. My typical choice is a &lt;TAB&gt;.&lt;BR /&gt;&lt;BR /&gt;Your data should then look like this:&lt;BR /&gt;412-99-3412&lt;TAB&gt;08/01/2002&lt;TAB&gt;5.75&lt;TAB&gt;Mary Rice&lt;TAB&gt;Pencils and Paper&lt;LF&gt;&lt;BR /&gt;&lt;BR /&gt;Now change your fscanf to look like this:&lt;BR /&gt;n = fscanf(infile,"%s\t%s\t%lf\t%[^\t\n]\t%[^\t\r\n",account_no,date,&amp;amp;amount,name,description); &lt;BR /&gt;&lt;BR /&gt;Note the %[^\t\n] that means keep scanning until you see a TAB or LF and load the string with that pattern. I left the earlier fields as %s because they seem to not have whitespace.&lt;BR /&gt;&lt;BR /&gt;That should fix you, Clay&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/LF&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;</description>
      <pubDate>Fri, 23 Aug 2002 19:18:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793099#M720506</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-08-23T19:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: fscanf is broken?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793100#M720507</link>
      <description>Thanks Clay! As usual a truly "magical" answer. I changed the printfs in my awk program to use tabs and now I don't need the quotes at all.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Mary</description>
      <pubDate>Fri, 23 Aug 2002 20:20:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fscanf-is-broken/m-p/2793100#M720507</guid>
      <dc:creator>Mary Rice</dc:creator>
      <dc:date>2002-08-23T20:20:12Z</dc:date>
    </item>
  </channel>
</rss>

