程序:
while((ch4=getc(fpGcode) )!= EOF)
......... #if 1
/*key: make sure only once -(ch3Enter == '\n')*/
if((ch3Enter == '\n'))
{
flagDelay = 0;
}
if((ch3Enter == '<')&& (ch1Cur == 'D'))
{
flagDelay = 1;
flagDelayRightSharp = 0;
flagTemp = 0;
/*Delay 无效,仅仅保留数字字符*/
memset(DelayBuf, '\0', GcodeBUFSIZE);
#if 0
printf("<lineDelay=%ld>#ch1Cur=%c\n", line, ch1Cur);
#endif
}
if(flagDelay == 1)
{
flagTemp++;
// printf("%c", ch1Cur);
#if 1
if((ch3Enter == 'y') &&ch1Cur == '>')
{
flagDelayRightSharp = 1;
posDelay = 0;
}
#if 1
if(ch1Cur == '>')
continue;
if(ch1Cur == ' ')
continue;
#endif
#endif
if(flagDelayRightSharp == 1 &&(ch1Cur != '\n'))
{
printf("[%c]", ch1Cur);
DelayBuf[posDelay] = ch1Cur;
printf("<%ld>\n", posDelay);
posDelay++;
}
if((ch1Cur == '\n'))
{
DelayBuf[posDelay-1] = '\0';
printf("<lineDelay=%ld><posDelay=%ld>DelayBuf=%s\n", line, (posDelay-1), DelayBuf);
printf("flagTemp=%d<<<<<<<<<<<\n\n", flagTemp);
}
}
#endif
运行:
<lineDelay=22415><posDelay=5>DelayBuf=
flagTemp=15<<<<<<<<<<<
[4]<0>
[8]<1>
[0]<2>
[0]<3>
]<4>
<lineDelay=22421><posDelay=4>DelayBuf=
flagTemp=13<<<<<<<<<<<
[1]<0>
[2]<1>
[0]<2>
[0]<3>
[0]<4>
]<5>
<lineDelay=22429><posDelay=5>DelayBuf=
flagTemp=15<<<<<<<<<<<
[4]<0>
[8]<1>
[0]<2>
[0]<3>
]<4>
<lineDelay=22435><posDelay=4>DelayBuf=
flagTemp=13<<<<<<<<<<<
bug1:“]<4>”.“[”丢失
bug2: "DelayBuf="字符数组无输出