帧头 帧尾问题
来源:互联网 发布:md5算法c 实现 编辑:程序博客网 时间:2024/04/30 19:48
#include <stdio.h>
#include <string.h>
char *head_count(char *str, char *head)//找出帧头前面的字符串
{
char *temp;
int size_head = strlen(head);
int count1 = 0;
int head_flag = 0;
if(str == NULL || head == NULL)
{
return NULL;
}
if(strlen(str) < strlen(head))
{
return NULL;
}
while(*str != '\0' && !head_flag)//判断找出dead
{
while(*str == *head)
{
str++;
head++;
count1++;
if(count1 == size_head)
{
head_flag = 1;
temp = str - size_head;//temp表示帧头出现位置前的字符
break;
}
}
str++;
}
if(head_flag)
{
return temp;
}
else
{
printf("error!");
}
}
char *tail_count(char *str, char *tail)//找出到帧尾为止的所有的字符串
{
if(str == NULL || tail == NULL)
{
return NULL;
}
if(strlen(str) < strlen(tail))
{
return NULL;
}
int size_tail = strlen(tail);
int count2 = 0;
int tail_flag = 0;
int head_flag = 1;
if(head_flag)
{
while(*str != '\0' && !tail_flag)//判断寻找出帧尾
{
while(*str == *tail)
{
str++;
tail++;
count2++;
if(size_tail == count2)
{
tail_flag = 1;
break;
}
}
str++;
}
}
if(tail_flag)
{
return str - 1;//返回的是到帧尾结束的字符串
}
else
{
printf("error!");
}
}
int main()
{
int i;
char *str = "asdheadhauboisoktail";
char *head = "head";
char *tail = "tail";
char *str_head = head_count(str, head);
char *str_tail = tail_count(str,tail);
printf("输入的字符串为:");
printf("%s\n",str);
printf("合法的帧为:");
int n = str_tail - str_head;
for(i = 0;i < n;i++)//输出合法的帧
{
printf("%c",*str_head);
str_head++;
}
printf("\n");
return 0;
}
0 0
- 帧头 帧尾问题
- IP头,TCP头,UDP头,MAC帧头定义
- IP头,TCP头,UDP头,MAC帧头定义
- IP头,TCP头,UDP头,MAC帧头定义
- IP头,TCP头,UDP头,MAC帧头定义
- 关于修改以太网帧头类型字段引发的问题
- MAC、IP头、TCP头、UDP头帧格式、详解
- MAC、IP头、TCP头、UDP头帧格式、详解
- h264序列头,帧头信息
- UNIX网络编程0 IP头,TCP头,UDP头,MAC帧头定义
- C++头文件问题,
- 头文件包含问题
- QT4头文件问题
- 头文件问题001
- 头文件包含问题
- 头文件问题
- cout头文件问题
- 头文件冲突问题
- java MVC设计模式
- HTML5启程
- 对拍
- springMVC - Controller
- 四轴的方案设计
- 帧头 帧尾问题
- Solidity 文档--第一章:智能合约入门
- 简单认识Toast
- MTD和 uboot中的bootargs 下属 mtdparts
- 感悟与思考-《无间道》电影思考
- 山科大judge online 1085 : 兔子的繁殖问题
- C语言正则表达式
- Vue--基础模板语法以及计算属性
- Leetcode2: Add Two Numbers