/*
* @Author: ShiWenYue
* @Date: 2022-05-30 14:47:22
* @LastEditors: ShiWenYue
* @LastEditTime: 2022-05-30 14:57:50
* @FilePath: \Linuxc\STRSTR.c
* @Description:
*
* Copyright (c) 2022 by SWY/KS, All Rights Reserved.
*/
#include <stdio.h>
#include <string.h>
#define SUCCESS 0
int CharSub(char *pcBuf, char *pcRes)
{
char *pcBegin = NULL;
char *pcEnd = NULL;
while(*pcBuf!='*')
{
if(*pcBuf == '#')
{
pcBegin=pcBuf;
}
pcBuf++;
}
pcEnd = strstr(pcBuf, "*");
if(pcBegin == NULL || pcEnd == NULL || pcBegin > pcEnd)
{
//返回错误消息 要求重发信息
}
else
{
pcBegin += strlen("#");
memcpy(pcRes, pcBegin, pcEnd-pcBegin);
}
return SUCCESS;
}
这是一个在通讯中使用的程序,我的通讯可能会出现起始位发送了之后没有发送完的情况,第二次发送的时候还是会发送起始位,所以通过截断函数截取最后一次出现的起始位到第一次出现的截止位的数据
测试情况如下
测试程序
结果