Re: Why is scanf such a nightmare to use?
- From: "BGB / cr88192" <cr88192@xxxxxxxxxxx>
- Date: Thu, 2 Sep 2010 09:41:21 -0700
"Guillaume Dargaud" <use_the_contact_form@xxxxxxxxxxxxxxxx> wrote in message
news:i5nq9i$2df$1@xxxxxxxxxxxxxxxxxxx
Whenever I try to use scanf I always get into some kind of trouble and
revert to strtok or similar finer grain functions.
I commonly copy around a variant of a "split" function, which basically
breaks up a string into a series of tokens (returned as 'char **', usually
allocated in temporary/volatile buffers which are prone to being overwritten
with later stuff).
for more advanced uses, I often use a tokenizer, which splits a string into
a set of syntax-specific tokens.
Example:
I have this string:
2010/09/02 11:03:57 Test
Where the 1st space is a space while the 2nd one is a tab.
I want to read it into two substrings, separating at the tab:
scanf(Str, "%s\t%s", DateTime, Target);
But I end up with:
DateTime=2010/09/02
Target=11:03:57
Why ?!?
because there is a space...
the example string would be read as 3 substrings, not 2.
.
- References:
- Why is scanf such a nightmare to use?
- From: Guillaume Dargaud
- Why is scanf such a nightmare to use?
- Prev by Date: Re: Three stupid C questions
- Next by Date: Re: breaking from a loop only works when I compile with optimisation
- Previous by thread: Re: Why is scanf such a nightmare to use?
- Next by thread: Re: Why is scanf such a nightmare to use?
- Index(es):
Relevant Pages
|