#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i=0;
char * ok1=NULL;
char * ok2=NULL;
char * ok3=NULL;
char * ok4="L";
char pp[150];
memset(&pp,0x00,sizeof(pp));
strcpy(pp,"1|KHP2013091600000|一号目标|s|640202198705201013|6375884367170130|D999|一号目标定投|s|||||D99|100|200|10000|1000000|");
ok3=pp;
ok1=strsep(&ok3,"|");
while(strcmp(ok3,"")!=0)
{
ok2=strsep(&ok3,"|");
if( strcmp(ok2,"") == 0 )
sprintf(ok1,"%s%s",ok1,ok4);
else
sprintf(ok1,"%s%s",ok1,ok2);
}
printf("%s\n",ok1);
return 0;
}
为什么 sprintf(ok1,"%s%s",ok1,ok4);这句会改变ok3和ok2的值? 实现的是把|替换为ctrl+b 并且连续的竖线之间用l分割
写错了。。。不过不影响结果。。。。