c语言中tag,c语言字符串匹配的问题?

晕!这就是最简单的了,你把头文件string.h包含起来调用strstr()函数就完成了。

string.h的库函数strstr()帮你完成此项功能,strstr()的功能就是在一个字符串中查找另一个字符串。下面是测试函数及strstr()函数。

#include

#include

#include

int main(void) /*测试strstr()*/

{

char *A="abcdefghi",*B,*C;

B = (char*)malloc(10);

memset(B, 0, sizeof(B));

C = (char*)malloc(10);

memset(C, 0, sizeof(C));

B[0]='f';B[1]='g';B[2]='h';

C = strstr(A,B);

printf("A=\"%s\"\n",A);

printf("B=\"%s\"\n",B);

printf("C=\"%s\"\n",C);

return 0;

}

#if 0

/*strstr()函数的返回值为s中匹配字窜的地址*/

char * strstr

(

const char * s,        /* string to search */

const char * find      /* substring to look for */

)

{

char *t1;

char *t2;

char c;

char c2;

if ((c = *find++) == 0)  /* an empty string */

return ((char *)(s));

for (;;)

{

while (((c2 = *s++) != 0) && (c2 != c))

;

if (c2 == 0)

return (NULL);

t1 = (char *)(s);

t2 = (char *)(find);

while (((c2 = *t2++) != 0) && (*t1++ == c2))

;

if (c2 == 0)

return ((char *)(s - 1));

}

}

#endif

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值