Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1567516
  • 博文数量: 354
  • 博客积分: 8137
  • 博客等级: 中将
  • 技术积分: 5137
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-26 15:40
文章分类

全部博文(354)

文章存档

2010年(300)

2009年(54)

分类: C/C++

2010-06-24 06:33:34

#include <stdio.h>
#include <stdlib.h>

int find_substr(char* s1, char* s2);

int main(int argc, char *argv[])
{
    if(find_substr("C is fun", "is") != -1)
        printf("Substring is found.\n");
    system("pause");
    return 0;
}

int find_substr(char* s1, char* s2)
{
    register int t;
    char *p, *p2;

    for(t = 0; s1[t]; t++)
    {
        p = &s1[t];
        p2 = s2;

        while(*p2 && *p2 == *p)
        {
            p++;
            p2++;
        }
        if(! *p2)
            return t;
    }
    return -1;
}


阅读(1229) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~