简体   繁体   中英

Reading floats from string as 2 integers

I'm trying to read floats from string splitting them up to 2 integers.

sscanf(line, "%d.%d", &dec, &frac));

This works with strings like this:

"0.25"

But if theres an optional sign before the number, it doesn't work anymore.

"-0.25"

How can i 'tell' sscanf, that there might be an optional sign before the number?

据我所知%d很好,因为它用于有符号整数,但是这里的问题来自-00的事实……您将不得不找到一种解决方法,因为我认为您找不到一个特定情况下的简单明了方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM