Solved

sscanf: tab character in input string?

Posted on 2013-06-17
4
407 Views
Last Modified: 2013-06-17
Ah hello

I have the following code, not written by myself, designed to parse out field/value pairs from an INI file:
	char txt[100], tmp[100];
	strcpy(txt, "FIELD=VALUE");
	
	if (sscanf( txt, " \t%[^=]", tmp ) == 1)
	{
		// Do stuff with tmp
	}

Open in new window


Now, being reasonably competent with what sscanf does, I find myself confused as to the explicit space and tab character in the input string.  Moreoever, with 'txt' not having any spaces or tab characters in it, I am surprised that 'tmp' still holds "VALUE" after the call.

Can someone explain what the \t and space could be for here please?

TIA
0
Comment
Question by:mrwad99
  • 2
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 39253236
since %[ supresses the usual skip of leading white space,  the  \t and space explicitly skip any amount of white space, including none
but it seems redundant to have both  \t and space
and tmp should hold "FIELD"  after the call, not "VALUE"
0
 
LVL 19

Author Comment

by:mrwad99
ID: 39253282
Thanks!

*Sigh*, yes: Ozo sorry the value of tmp is of course FIELD.

Yes, according to http://linux.die.net/man/3/sscanf it seems that using [ will supress skipping of leading white space.  (Not that I doubted you, just for others reading :))

But why the explicit single space and \t?  I tried with just the space, and just the tab, and both worked the same...any idea?
0
 
LVL 84

Expert Comment

by:ozo
ID: 39253296
perhaps the author did not know that either would suffice
0
 
LVL 19

Author Closing Comment

by:mrwad99
ID: 39253322
Thank you very much :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now