字符串练习——识别合法帧

输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来。
提示:帧头和帧尾分别是head和tail 。字符串 ”asdheadhauboisoktail”中headhauboisoktail是合法帧

#include <stdio.h>
#include <string.h>
int fun(char *ptr,char *head,char *tail)
{
char *temp;
while(*ptr != '\0')
{
if(strncmp(ptr,head,strlen(head)) == 0)
{
temp = ptr;
ptr+=strlen(head);
while(*ptr != '\0')
{
if(strncmp(ptr,tail,strlen(tail)) == 0)
{
*(ptr+strlen(tail)) = '\0';
  printf("%s\n",temp);
return 0;
       }
ptr++;
}
printf("find head not find tail!\n");
break;
}
else
ptr++;
}
return 0;
}
int main()
{ 
char src[100];
char head[20];
char tail[20];
printf("please input string:\n");
scanf("%s",src);
printf("please input head:\n");
scanf("%s",head);
printf("please input tail:\n");
scanf("%s",tail);


printf("the result:\n");
fun(src,head,tail);
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值