请各位高手帮忙看一下,我这个从串口接受的数据中,提取出想要的数据做法正确吗:还有请问高手:在VC中如何把这些字符转化成 浮点型的数
例如程序 G01 X34 Y48 Z45 A-23.4 C173 S3784 M10
G03 X47 Y78 Z27 A75 C57 S865
.......
我想从这些代码中把字符A和S之后的数据提出来 S后面的3784 我以S为标准寻找,空格作为数据结束的标志int i; char a[i]; // a[i]存放是接受过来的字符串
len= Getlen() // 字符串长度
char b[3] //
for(i=0;i<len; )
{
if('s'==a[i])
{ i++;
b[0]=a[i];
i++;
if(i>len) breake;
else if(a[i]=" ")
continue;// 重新循环
b[1]=a[i];
i++;
if(i>len) breake;
if(a[i]=" ")
continue;// 重新循
b[2]=a[i];
i++;
if(i>len) breake;
if(a[i]=" ")
continue;// 重新循
b[3]=a[i];
}
i++;
}我想取得S后面的数据,用数据后面空格判断所取数据结束,请问高手有没有更好的办法 (在 MFC中使用)
例如程序 G01 X34 Y48 Z45 A-23.4 C173 S3784 M10
G03 X47 Y78 Z27 A75 C57 S865
.......
我想从这些代码中把字符A和S之后的数据提出来 S后面的3784 我以S为标准寻找,空格作为数据结束的标志int i; char a[i]; // a[i]存放是接受过来的字符串
len= Getlen() // 字符串长度
char b[3] //
for(i=0;i<len; )
{
if('s'==a[i])
{ i++;
b[0]=a[i];
i++;
if(i>len) breake;
else if(a[i]=" ")
continue;// 重新循环
b[1]=a[i];
i++;
if(i>len) breake;
if(a[i]=" ")
continue;// 重新循
b[2]=a[i];
i++;
if(i>len) breake;
if(a[i]=" ")
continue;// 重新循
b[3]=a[i];
}
i++;
}我想取得S后面的数据,用数据后面空格判断所取数据结束,请问高手有没有更好的办法 (在 MFC中使用)
int i=0;
while ( i<len )
{
CString str(p+i);
i += str.GetLength();
double a_follow=0.0,s_follow=0.0;
int ret = str.Find('A');
if ( ret>0 )
{
CString str_tmp = str.Mid(ret,str.GetLength()-ret);
scanf(str_tmp.GetBuffer(0),"A%f ",&a_follow);
}
ret = str.Find('S');
if ( ret>0 )
{
CString str_tmp = str.Mid(ret,str.GetLength()-ret);
scanf(str_tmp.GetBuffer(0),"S%f ",&a_follow);
}
}
……