Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Scanf and wildcard

Reply
Thread Tools

Scanf and wildcard

 
 
raphfrk@gmail.com
Guest
Posts: n/a
 
      09-06-2008
I have a string that I want to extract some fields out of.

For example

ZABDE10FGH20
ZFDSF11FGG21
(etc)

I might want to extract the 2 sets of numbers.

One option would be to use throwaway buffers.

char buffer1[6];
int num1;
char buffer[4];
int num2;

and then use

fscanf( fp , "%5s%2d%3s%d" , buffer1, num1 , buffer2, num2 );

Is there a better way to get scanf to skip lines other than having it
write them to an unused buffer ?
 
Reply With Quote
 
 
 
 
vippstar@gmail.com
Guest
Posts: n/a
 
      09-06-2008
On Sep 6, 10:36 pm, raph...@gmail.com wrote:

<snip>

> Is there a better way to get scanf to skip lines other than having it
> write them to an unused buffer ?


you can discard the matched result by using `*'.
Ie:
scanf("%*s%s", buf);

with input:
hello world

would read `world' into the buffer.
 
Reply With Quote
 
 
 
 
raphfrk@gmail.com
Guest
Posts: n/a
 
      09-06-2008
On Sep 6, 8:57 pm, vipps...@gmail.com wrote:
> On Sep 6, 10:36 pm, raph...@gmail.com wrote:
>
> <snip>
>
> > Is there a better way to get scanf to skip lines other than having it
> > write them to an unused buffer ?

>
> you can discard the matched result by using `*'.
> Ie:
> scanf("%*s%s", buf);
>
> with input:
> hello world
>
> would read `world' into the buffer.


Thanks
 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      09-06-2008
On 2008-09-06, <> wrote:
> On Sep 6, 10:36 pm, raph...@gmail.com wrote:
>
><snip>
>
>> Is there a better way to get scanf to skip lines other than having it
>> write them to an unused buffer ?

>
> you can discard the matched result by using `*'.
> Ie:
> scanf("%*s%s", buf);
>
> with input:
> hello world
>
> would read `world' into the buffer.


Yikes! scanf("%s") should not be used without a length qualifier,
otherwise it is effectively gets().

--
Andrew Poelstra
To email me, use the above email addresss with .com set to .net
 
Reply With Quote
 
vippstar@gmail.com
Guest
Posts: n/a
 
      09-07-2008
On Sep 6, 11:35 pm, Andrew Poelstra <apoels...@supernova.home> wrote:
> On 2008-09-06, vipps...@gmail.com <vipps...@gmail.com> wrote:
>
> > On Sep 6, 10:36 pm, raph...@gmail.com wrote:

>
> ><snip>

>
> >> Is there a better way to get scanf to skip lines other than having it
> >> write them to an unused buffer ?

>
> > you can discard the matched result by using `*'.
> > Ie:
> > scanf("%*s%s", buf);

>
> > with input:
> > hello world

>
> > would read `world' into the buffer.

>
> Yikes! scanf("%s") should not be used without a length qualifier,
> otherwise it is effectively gets().


Don't worry. buf is long enough
 
Reply With Quote
 
Obnoxious User
Guest
Posts: n/a
 
      09-07-2008
On Sun, 07 Sep 2008 00:26:06 -0700, vippstar wrote:

> On Sep 6, 11:35 pm, Andrew Poelstra <apoels...@supernova.home> wrote:
>> On 2008-09-06, vipps...@gmail.com <vipps...@gmail.com> wrote:
>>
>> > On Sep 6, 10:36 pm, raph...@gmail.com wrote:

>>
>> ><snip>

>>
>> >> Is there a better way to get scanf to skip lines other than having
>> >> it write them to an unused buffer ?

>>
>> > you can discard the matched result by using `*'. Ie:
>> > scanf("%*s%s", buf);

>>
>> > with input:
>> > hello world

>>
>> > would read `world' into the buffer.

>>
>> Yikes! scanf("%s") should not be used without a length qualifier,
>> otherwise it is effectively gets().

>
> Don't worry. buf is long enough


That's just hilarious Fancy reading that
excuse as a comment in some core system.

--
OU
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-07-2008
wrote:
> Andrew Poelstra <apoels...@supernova.home> wrote:
>

.... snip ...
>
>> Yikes! scanf("%s") should not be used without a length qualifier,
>> otherwise it is effectively gets().

>
> Don't worry. buf is long enough


How did you manage to define an infinitely large buf?

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcard String Comparisons: Set Pattern to a Wildcard Source chaoticcranium@gmail.com Python 7 10-05-2010 09:26 PM
difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 18 05-02-2006 10:53 AM
scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc. =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 185 04-03-2006 02:49 PM
Redirects with ASP.NET 2.0 and wildcard mappings SlimFlem ASP .Net 7 12-22-2005 09:26 PM
difference between "import" with and without wildcard. Peter Rilling Java 1 03-25-2005 07:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57