Chinaunix首页 | 论坛 | 博客
  • 博客访问: 817109
  • 博文数量: 321
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 936
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-23 11:25
文章分类

全部博文(321)

文章存档

2017年(1)

2016年(10)

2015年(61)

2014年(187)

2013年(62)

分类: C/C++

2014-06-24 10:09:12

#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;
}


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