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

提示:帧头和帧尾分别是headtail  字符串”asdheadhauboisoktail”headhauboisoktail是合法帧

  1 # include <stdio.h>
  2 # include <string.h>
  3
  4 void distinguish(char *s1)
  5 {
  6     int i, j, len;
  7     char *s2;
  8
  9     len = strlen(s1);
 10     for(i=0;i<len;i++)
 11     {
 12         if(strncmp(s1,"head",4)==0)
 13         {
 14             break;
 15         }
 16         s1++;
 17     }
 18     s2=s1;
 19     for(j=0;j<len-i;j++)
 20     {
 21         if(strncmp(s2,"tail",4)==0)
 22         {
 23             s2=s2+4;
 24             *s2=0;
 25             break;
 26         }
 27         s2++;
 28     }
 29     if(i>=len || j>=len-i)
 30     {
 31         printf("ERROR!");
 32     }
 33     printf("Legitimate frame is : %s\n",s1);
 34 }
 35
 36 int main()
 37 {
 38     char str1[100];
 39
 40     printf("Please input a string include head and tail:\n");
 41     scanf("%s",str1);
 42
 43     distinguish(str1);
 44
 45     return 0;
 46 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值