打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
字符串不分大小写定位C语言 stristr.c
stristr.c:源码内容
/* +++Date last modified: 05-Jul-1997 */
/*
** Designation:  StriStr
**
** Call syntax:  char *stristr(char *String, char *Pattern)
**
** Description:  This function is an ANSI version of strstr() with
**               case insensitivity.
**
** Return item:  char *pointer if Pattern is found in String, else
**               pointer to 0
**
** Rev History:  07/04/95  Bob Stout  ANSI-fy
**               02/03/94  Fred Cole  Original
**
** Hereby donated to public domain.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "snip_str.h"
typedef unsigned int uint;
#if defined(__cplusplus) && __cplusplus
 extern "C" {
#endif
char *stristr(const char *String, const char *Pattern)
{
      char *pptr, *sptr, *start;
      uint  slen, plen;
      for (start = (char *)String,
           pptr  = (char *)Pattern,
           slen  = strlen(String),
           plen  = strlen(Pattern);
           /* while string length not shorter than pattern length */
           slen >= plen;
           start++, slen--)
      {
            /* find start of pattern in string */
            while (toupper(*start) != toupper(*Pattern))
            {
                  start++;
                  slen--;
                  /* if pattern longer than string */
                  if (slen < plen)
                        return(NULL);
            }
            sptr = start;
            pptr = (char *)Pattern;
            while (toupper(*sptr) == toupper(*pptr))
            {
                  sptr++;
                  pptr++;
                  /* if end of pattern then pattern was found */
                  if ('' == *pptr)
                        return (start);
            }
      }
      return(NULL);
}
#if defined(__cplusplus) && __cplusplus
 }
#endif
#ifdef TEST
int main(void)
{
      char buffer[80] = "heLLo, HELLO, hello, hELLo, HellO";
      char *sptr = buffer;
      while (0 != (sptr = stristr(sptr, "hello")))
            printf("Found %5.5s!n", sptr++);
      return(0);
}
#endif /* TEST */

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
搜集的一些腾讯笔试题
c与c++程序连接问题
如何用VC编写供JAVA调用的DLL
s05 - Finding a Motif in DNA
Unity3d与iOS交互开发
java中判断字符串是否是一个整数(转载)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服