c - Use sscanf for regex purpose -
i have string str
, if str
composed of pure digits, extract digits int
, if not, extract nothing or 0.
for example,
str = "12345"; // composed of pure digits, extract 12345 str = "123abc"; // not pure digits, extract nothing or 0
can using sscanf
? how?
int value; char unused; if (1 == sscanf(mystring, "%d%c", &value, &unused)) { // success } else { // bad input }
Comments
Post a Comment