#include <reg52.h>
#include <stdlib.h>
typedef struct
{
int i;
int d;
} StepMoto;
StepMoto moto[3];
void extract(char *p);
char * extractString(char *p, int i);
void main()
{
char c[] = "#3p11234#1p112345#2p112346#s";
extract(c);
while(1);
}
void extract(char *pn)
{
while (*pn != 's')
{
if (*pn++ == '#')
{
switch (*pn)
{
case '1':
pn = extractString(pn, 0);
break;
case '2':
pn = extractString(pn, 1);
break;
case '3':
pn = extractString(pn, 2);
break;
default:
break;
}
}
}
}
char * extractString(char *p, int i)
{
char cp, ch[10];
int j = 0;
while (*p != '#')
{
ch[j++] = *p++;
}
cp = ch[2];
moto[i].d = atoi(&cp); //就是这句 转换后就出错。
moto[i].i = atoi(&ch[3]);
return p;
}
|