找合法针

来源:互联网 发布:python自动化测试视频 编辑:程序博客网 时间:2024/04/27 13:48

asdheadhauboisoktailgdg找这个的合法针,需要我们先扫描到我们需要的head(这个是针头),tail(这个是针尾)下面的是代码

#include <stdio.h>#include <string.h>// 在字符串str中寻找字符串sub,如果找到返回从sub开始的字符串char *findStr(char* str, char *sub){    char *p = NULL;    int len = strlen(sub);  // 算字串的长度    while(*str)    {        if (strncmp(str, sub, len) == 0)        {            p = str;            break;        }        str++;    }    return p;}// 找合法帧void findFrame(char *str, char *head, char *tail){    char *phead = findStr(str, head);  // 找帧头的位置    char *ptail = findStr(str, tail);  // 找帧尾的位置    if (phead != NULL && ptail != NULL)    {        ptail += strlen(tail);        *ptail = '\0';        printf ("%s\n", phead);    }}int main(){    char str[] = "asdheadhauboisoktailgdg";    findFrame(str, "head", "tail");    return 0;}
原创粉丝点击