小编vbr*_*sch的帖子

sscanf似乎在uint变量和c中的int变量上表现不同

我正在开发一个微控制器程序,并希望使用从字符串中读取数字到整数变量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_tuint16_t整数:

#include <stdio.h>
#include <stdint.h>
int main()
{
    uint16_t power;
    uint8_t …
Run Code Online (Sandbox Code Playgroud)

c int scanf uint

4
推荐指数
1
解决办法
287
查看次数

标签 统计

c ×1

int ×1

scanf ×1

uint ×1