我正在开发一个微控制器程序,并希望使用从字符串中读取数字到整数变量sscanf().问题是我在使用int声明vs uint8_t或时得到了不同的行为uint16_t.
这int用于变量声明:
#include <stdio.h>
#include <stdint.h>
int main()
{
int power;
int hr;
int cadence;
sscanf("204 67 94","%d %d %d",&power, &hr, &cadence);
printf("power: %d, hr: %d, cadence: %d", power, hr, cadence);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当放入https://www.onlinegdb.com/返回时:
power: 204, hr: 67, cadence: 94
...Program finished with exit code 0
Press ENTER to exit console.
Run Code Online (Sandbox Code Playgroud)
这是我期望它表现的方式.
而使用uint8_t和uint16_t整数:
#include <stdio.h>
#include <stdint.h>
int main()
{
uint16_t power;
uint8_t …Run Code Online (Sandbox Code Playgroud)