473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Scanf and wildcard

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 ?
Sep 6 '08 #1
8 7208
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.
Sep 6 '08 #2
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
Sep 6 '08 #3
On 2008-09-06, vi******@gmail.com <vi******@gmail.comwrote:
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 ap*******@wpsoftware.com
To email me, use the above email addresss with .com set to .net
Sep 6 '08 #4
On Sep 6, 11:35 pm, Andrew Poelstra <apoels...@supernova.homewrote:
On 2008-09-06, vipps...@gmail.com <vipps...@gmail.comwrote:
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
Sep 7 '08 #5
vi******@gmail.com said:
On Sep 6, 11:35 pm, Andrew Poelstra <apoels...@supernova.homewrote:
<snip>
>Yikes! scanf("%s") should not be used without a length qualifier,
otherwise it is effectively gets().

Don't worry. buf is long enough
I trust you mean that as a joke?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 7 '08 #6
vi******@gmail.com wrote:
Andrew Poelstra <apoels...@supernova.homewrote:
.... 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.
Sep 7 '08 #7
On Sep 7, 10:38 am, Richard Heathfield <r...@see.sig.invalidwrote:
vipps...@gmail.com said:
On Sep 6, 11:35 pm, Andrew Poelstra <apoels...@supernova.homewrote:

<snip>
Yikes! scanf("%s") should not be used without a length qualifier,
otherwise it is effectively gets().
Don't worry. buf is long enough

I trust you mean that as a joke?
Yes, I guess a smiley was missing. ;-)
Sep 7 '08 #8
On Sun, 07 Sep 2008 00:26:06 -0700, vippstar wrote:
On Sep 6, 11:35 pm, Andrew Poelstra <apoels...@supernova.homewrote:
>On 2008-09-06, vipps...@gmail.com <vipps...@gmail.comwrote:
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
Sep 7 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Generic Usenet Account | last post by:
Here's the requirement that I am trying to satisfy: Handle wildcards in STL such that the wildcard entry is encountered before non-wildcard entries while traversing containers like sets and...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
12
by: B Thomas | last post by:
Hi, I was reading O'Reilly's "Practical C programming" book and it warns against the use of scanf, suggesting to avoid using it completely . Instead it recomends to use using fgets and sscanf....
7
by: hugo27 | last post by:
obrhy8 June 18, 2004 Most compilers define EOF as -1. I'm just putting my toes in the water with a student's model named Miracle C. The ..h documentation of this compiler does state that when...
3
by: Adam | last post by:
Its my understanding that in asp.net 2.0 you can write an httpmodule that will acts as a wildcard handler and pass requests on to the proper engine, for instance, asp or perl for example, In the...
7
by: SlimFlem | last post by:
I have searched hard for 2 days on this and keep hitting a wall. I have a custom IHttpHandler setup to do Url mappings to prop up some old Urls for our site. I have also created a wildcard...
6
by: Jan Kucera | last post by:
Hi, does anybody know about wildcard mapping ASP.NET 2 in IIS6? Any tutorial? Thanks, Jan
14
by: main() | last post by:
I know this is the problem that most newbies get into. #include<stdio.h> int main(void) { char a; scanf("%c",&a); /*1st scanf */ printf("%c\n",a); scanf("%c",&a); /*2nd scanf*/...
1
by: Lucvdv | last post by:
In my assembly.vb files, I'm using the revision/build wildcard style: <Assembly: AssemblyVersion("3.0.*")> <Assembly: AssemblyFileVersion("3.0.*")> This onkly seems to work in projects that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.