Solved

sscanf: tab character in input string?

Posted on 2013-06-17
4
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 and use structures 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.

734 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