提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhauboisoktail是合法帧
#include <stdio.h>
#include <string.h>
int main()
{
char str[30] = {0};
char a[30] = {0};
char b[30] = {0};
printf("请输入一个字符串,侦头和侦尾:\n");
scanf("%s%s%s",str,a,b);
char *ptr = str;
char *a1 = a;
char *b1 = b;
char *a2 = NULL;
int len_a, len_b, i;
len_a = strlen(a);
len_b = strlen(b);
while(*ptr != '\0')
{
if(strncmp(ptr, a1, len_a) == 0)
{
a2 = ptr;
while(*a2 != '\0')
{
if(strncmp(a2, b1, len_b) == 0)
{
int sum = a2 - ptr + len_b;
for(i = 0; i < sum; i++)
{
printf("%c",*ptr);
ptr++;
}
}
else
{
puts("error\n");
return 0;
}
a2++;
}
}
else
{
puts("error\n");
break;
}
ptr++;
}
printf("\n");
return 0;
}