How can I get an int next to a word using scanf?

11 Views Asked by At

How can I extract an int contained in a string like att249 or berlin32 using sscanf ?

I tried

"%s%d" 

Which doesn't work because the %s scan doesn't stop on the 2

1

There are 1 best solutions below

0
On

After asking on the OCaml discord, I got the answer on how to achieve this :

"%[^0-9]%d"

Which works well because %[^0-9] scan until it encounters a digit.

Being a complete beginner in scanf, I don't know if it's the best way to achieve it though.