- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- fscanf is broken?
Operating System - HP-UX
1755616
Members
3472
Online
108836
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 12:10 PM
тАО08-23-2002 12:10 PM
Hello Experts,
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.
Each line of data looks like this:
Account Number Date Amount Name Description
412-99-3412 08/01/2002 5.75 "Mary Rice" "Pencils and Paper"
541-45-8911 08/02/2002 121.90 "Robert Rice" "Copier Toner"
I am using an fscanf function like this
n = fscanf(infile,"%s %s %lf %s %s\n",account_no,date,&amount,name,description);
All the variable types are correct. The first three variables work perfectly but Name = ""Robert" and Description = "Rice"". What am i doing wrong?
Please don't ask to man scanf; I've done that!!!
Thanks for your help,
Mary
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.
Each line of data looks like this:
Account Number Date Amount Name Description
412-99-3412 08/01/2002 5.75 "Mary Rice" "Pencils and Paper"
541-45-8911 08/02/2002 121.90 "Robert Rice" "Copier Toner"
I am using an fscanf function like this
n = fscanf(infile,"%s %s %lf %s %s\n",account_no,date,&amount,name,description);
All the variable types are correct. The first three variables work perfectly but Name = ""Robert" and Description = "Rice"". What am i doing wrong?
Please don't ask to man scanf; I've done that!!!
Thanks for your help,
Mary
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 12:18 PM
тАО08-23-2002 12:18 PM
Solution
Mary:
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.
Your data should then look like this:
412-99-341208/01/20025.75Mary RicePencils and Paper
Now change your fscanf to look like this:
n = fscanf(infile,"%s\t%s\t%lf\t%[^\t\n]\t%[^\t\r\n",account_no,date,&amount,name,description);
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.
That should fix you, Clay
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
Your data should then look like this:
412-99-3412
Now change your fscanf to look like this:
n = fscanf(infile,"%s\t%s\t%lf\t%[^\t\n]\t%[^\t\r\n",account_no,date,&amount,name,description);
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.
That should fix you, Clay
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 01:20 PM
тАО08-23-2002 01:20 PM
Re: fscanf is broken?
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.
Thanks,
Mary
Thanks,
Mary
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP