Hi,
Can someone please tell me how to embed regular expression in
scanf, sscanf or fscanf. My guess is that it may be the same for all these io functions.
You can't.
There is only one thing which even comes close, and that is a scan set (or it's complement).
Eg.
[tt]scanf( "%[0-9]", myNumStr );[/tt]
Which in regex terms is [tt][0-9]+[/tt]
If you want anything more complicated than that, then the best thing to do is read a line using fgets(), then use one of the standard regex packages and parse the line yourself.
--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.