您可以使用标准库函数sscanf来提取字符串中的数据。以下是一个示例代码:

#include <stdio.h>

int main() {
    unsigned int temp;
    char *rxbuf = 'wdy:32';
    
    sscanf(rxbuf, 'wdy:%u', &temp);
    
    printf('temp = %u\n', temp);
    
    return 0;
}

在上述代码中,sscanf(rxbuf, 'wdy:%u', &temp)将会从字符串rxbuf中按照格式字符串'wdy:%u'提取出无符号整数,并将其赋值给temp变量。最后,通过printf函数打印出提取后的结果。

输出结果为:

temp = 32
C语言提取字符串中的数值:sscanf用法示例

原文地址: https://www.cveoy.top/t/topic/qinO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录