Solved

sscanf: tab character in input string?

Posted on 2013-06-17
4
411 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

810 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