LabWindows/CVI Scan( )函数

发布时间 2023-10-12 11:16:06作者: eiSouthBoy

背景介绍

Scan()可以将字符串按照用户 formatString 格式说明分解成多个组件。最多可以分解29个组件。

Scan()很强大且复杂,使用起来容易出错,但它却被频繁使用。

Scan()函数

函数头文件:#include <formatio.h>

函数原型:int Scan (void *Source, char Format_String[], ...);

将字符串:2023-10-10 10:09:00.100,1024,5.20,gbk2313,90.00 分成成字符串、整型、浮点型,即date="2023-10-10 10:09:00.100",id=1024,price=5.20,encode="gbk2312",total=90.00

/* 部分代码 */
char date[24] = {0}, encode[128] = {0};
int id = 0;
double price = 0, total = 0;
const char *buffer = "2023-10-10 10:09:00.100,1024,5.20,gbk2313,90.00";
Scan(buffer, "%s>%s[t44],%d,%f,%s[t44],%f", date, &id, &price, encode, &total);
printf("buffer=\"2023-10-10 10:09:00.100,1024,5.20,gbk2313,90.00\"\n");

printf("date=%s\n", date);
printf("id=%d\n", id);
printf("price=%f\n", price);
printf("encode=%s\n", encode);
printf("total=%f\n", total);

? 分解字符串中的目标字符串需要给出分隔符,例如:[t44],