Solved

sscanf: tab character in input string?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

867 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

16 Experts available now in Live!

Get 1:1 Help Now