Scanf and wildcard

R

raphfrk

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 ?
 
V

vippstar

On Sep 6, 10:36 pm, (e-mail address removed) wrote:

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.
 
R

raphfrk

On Sep 6, 10:36 pm, (e-mail address removed) wrote:



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

with input:
hello world

would read `world' into the buffer.

Thanks
 
A

Andrew Poelstra

On Sep 6, 10:36 pm, (e-mail address removed) wrote:



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().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top