您的位置:首页 > 其它

4.5题目: 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.

2017-04-03 14:59 453 查看
/*题目: 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.提示:帧头和帧尾分别是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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐