strstri.c

来自「VC源代码大全(精华版)」· C语言 代码 · 共 38 行

C
38
字号
/*
   strstri.c - case- insensitive version of strstr.
 */
#include    <stdlib.h>
#include    <string.h>

char *strstri (char *s1, char *s2)
{
char    *s, *t, *u;

    if ((s1 == NULL) || (s2 == NULL))
        return (NULL);
/*
    Copy the strings so we can upper case them
 */
    s = strdup (s1);
    if (s == NULL)
        return (NULL);
    t = strdup (s2);
    if (t == NULL)
        {
        free (s);
        return (NULL);
        }
    strupr (s);
    strupr (t);
/*
    Call strstr on the strings. If not NULL, take the
    difference between s and u and apply it to s1. Then
    set u to s1 for the return.
 */
    if ((u = strstr (s, t)) != NULL)
        u = s1 + (u - s);
    free (s);
    free (t);
    return (u);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?