本题要求实现一个字符串查找的简单函数。
函数接口定义:
            
            
              c
              
              
            
          
          char *search( char *s, char *t );
        函数search在字符串s中查找子串t,返回子串t在s中的首地址。若未找到,则返回NULL。
输入样例1:
            
            
              c
              
              
            
          
          The C Programming Language
ram
        输出样例1:
            
            
              c
              
              
            
          
          10
        输入样例2:
            
            
              c
              
              
            
          
          The C Programming Language
bored
        输出样例2:
            
            
              c
              
              
            
          
          -1
        具体程序:
            
            
              c
              
              
            
          
          #define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define MAXS 30
char* search(char* s, char* t);
int main()
{
    char s[MAXS], t[MAXS], * pos;
    gets(s);
    gets(t);
    pos = search(s, t);
    if (pos != NULL)
        printf("%d\n", pos - s);
    else
        printf("-1\n");
    return 0;
}
char* search(char* s, char* t)
{
    int i = 0;
    while (*(s + i) != '\0')
    {
        if (*(s + i) == *t)
        {
            int j = 0;
            while (*(t + j) != '\0')
            {
                if (*(s + i + j) != *(t + j))break;
                j++;
            }
            if (*(t + j) == '\0')
                return(s + i);
        }
        i++;
    }
    return NULL;
}
        运行效果:

