哪位高手来帮我看看下在c语言字符串中查找问题
例如 kdn字符串在 字符串dgkuokdnfbvdwfgks中的从左到右查找,查找出是第几个开始完全匹配.c语言怎么实现? strstr();函数 /***********************字符串查找*********************************功 能: 查找字符串
*形 参: char *s, char *t ;在s中查找t
*返 回 值: s_temp(t在s中的位置)成功 0 (失败 )
*备 注:
*****************************************************************/
char *mystrstr(char *s, char *t)
{
char *s_temp ; /*the s_temp point to the s*/
char *m_temp ; /*the mv_tmp used to move in the loop*/
char *t_temp ; /*point to the pattern string*/
if (s == 0 ||t == 0) return 0;
for (s_temp = s; *s_temp != '\0'; s_temp++)
{
m_temp = s_temp;
for (t_temp = t; *t_temp == *m_temp; t_temp++, m_temp++)
if (*t_temp == '\0') return s_temp;
if (*t_temp == '\0') return s_temp;
}
return 0;
} 楼上的函数不错,算法简洁! Jason022 发表于 2012-4-26 08:10
/***********************字符串查找********************************
*功 能: 查找字符串
*形 参:...
不知道怎么回事,for循环中的 变量 t_temp++,但它 一直不增加
页:
[1]