c语言用来查找字符串的函数是,C语言字符串查找函数

#define PARALENGTH 50

typedef struct Content_Type_Para{

char paraName[PARALENGTH];

char paraValue[PARALENGTH];

}ContentTypePara_t;

void setContentType(const char *content)

{

//content参数形如"application/bear;params1=XXXYYY,params2=ZZZZSSS"

char contentTypeName[PARALENGTH];

char contentTypeValue[PARALENGTH];

memset(contentTypeName, 0, PARALENGTH);

memset(contentTypeValue, 0, PARALENGTH);

int ContentTypeParasNumber = 0;        //参数个数

ContentTypePara_t contentTypeParas[5];   //参数数组

for(int k=0; k< 5; k++)

{

memset(contentTypeParas[k].paraName, 0, PARALENGTH);

memset(contentTypeParas[k].paraValue, 0, PARALENGTH);

}

//在临时空间里操作字符串

char *p;

char temp[1024];

memset(temp, 0, sizeof(temp));

strncpy(temp, content, strlen(content));

p = temp;

//临时子串

char *tp;

char subtemp[PARALENGTH];

memset(subtemp, 0, PARALENGTH);

tp = subtemp;

char flag;   //用来标识字符串的分割点

//字符串查找

for(; *p != '\0'; p++)

{

if((*p != '/')&&(*p != ';')&&(*p != '=')&&(*p != ','))   //连续的字符串,复制

{

*tp = *p;

tp++;

}

else if(*p =='/')                  //'/'之前的字符串是contentTypeName

{

strncpy(contentTypeName, subtemp, strlen(subtemp));

memset(subtemp, 0, strlen(subtemp));         //清空临时子串

tp = subtemp;

flag = '/';                      //标识一个子串的结束

}

else if(*p == ';')                 //如果参数之间使用',',那么这个头字段只有一个';'

{

if(flag == '/')                  //';'之前的flag一定是'/'

{

strncpy(contentTypeValue, subtemp, strlen(subtemp));

memset(subtemp, 0, strlen(subtemp));

tp = subtemp;

flag = ';';

}

}

else if(*p == '=')                  //参数的赋值使用'='

{

if((flag == ';') || (flag == ','))

{

strncpy(contentTypeParas[ContentTypeParasNumber].paraName, subtemp, strlen(subtemp));

memset(subtemp, 0, strlen(subtemp));

tp = subtemp;

flag = '=';

}

}

else if(*p == ',')

{

if(flag == '=')

{

strncpy(contentTypeParas[ContentTypeParasNumber].paraValue, subtemp, strlen(subtemp));

memset(subtemp, 0, strlen(subtemp));

tp = subtemp;

flag = ',';

ContentTypeParasNumber++;

}

}

}

//最后一个子串

if(flag == '=')

{

strncpy(contentTypeParas[ContentTypeParasNumber].paraValue, subtemp, strlen(subtemp));

memset(subtemp, 0, strlen(subtemp));

tp = subtemp;

ContentTypeParasNumber++;

}

else if(flag = '/')                  //没有参数的情况

{

strncpy(contentTypeValue, subtemp, strlen(subtemp));

memset(subtemp, 0, strlen(subtemp));

tp = subtemp;

}

printf("|*|*|***********************************************\n");

printf("|*|*|contentTypeName : %s \n", contentTypeName);

printf("|*|*|contentTypeValue : %s \n", contentTypeValue);

for(int i = 0; i

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值