c语言中使用sscanf函数读取字符串的数据时,字符串使用逗号(,)将数据隔开,但是如果2个逗号间没有数据时,将读取后续数据,这不是想要的结果。
使用的语句如图2 sscanf((const char*)b,"%*d,%*d,%*d,%[^,],%[^,]……")
如图1中第1行数据红色箭头部分,想得到的数据“a[0]=$GPSSV a[0]=3 a[1]=1 a[2]=09 a[3]=13 a[4]=80 a[5]=115 a[6]=51 a[7]=20 a[8]=31 a[9]=308 a[10]=空 a[11]=15 a[12]=57 a[13]=220 a[14]=空 a[15]=05 a[16]=50 a[17]=064 a[18]=52*74”
实际得到数据是“a[0]=$GPSSV a[0]=3 a[1]=1 a[2]=09 a[3]=13 a[4]=80 a[5]=115 a[6]=51 a[7]=20 a[8]=31 a[9]=308 a[10]=15 a[11]=57 a[12]=220 a[13]=05 a[14]=50 a[15]=064 a[16]=52*74 a[17]=空 a[18]=空”
如果没有数据,那就这样定义数据,中间使用空格或者0,1代表。。sscanf只是按照格式读取而已,没有数据定义,肯定是读取后面的数据了。
24,24, ,25,25