zoukankan      html  css  js  c++  java
  • (1)strchr

    const char * strchr ( const char * str, int character );
          char * strchr (       char * str, int character );
    Locate first occurrence of character in string

    Returns a pointer to the first occurrence of character in the C string str.

    The terminating null-character is considered part of the C string. Therefore, it can also be located in order to retrieve a pointer to the end of a string.

    Return: 第一次出现位置,出错则返回NULL

    strch.c源码

    char *
    strchr (s, c_in)
         const char *s;
         int c_in;
    {
      const unsigned char *char_ptr;
      const unsigned long int *longword_ptr;
      unsigned long int longword, magic_bits, charmask;
      unsigned char c;
    
      c = (unsigned char) c_in;
    
      /* Handle the first few characters by reading one character at a time.
         Do this until CHAR_PTR is aligned on a longword boundary.  */
      for (char_ptr = (const unsigned char *) s;
           ((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0;
           ++char_ptr)
        if (*char_ptr == c)
          return (void *) char_ptr;
        else if (*char_ptr == '')
          return NULL;
    
      /* All these elucidatory comments refer to 4-byte longwords,
         but the theory applies equally well to 8-byte longwords.  */
    
      longword_ptr = (unsigned long int *) char_ptr;
    
      /* Bits 31, 24, 16, and 8 of this number are zero.  Call these bits
         the "holes."  Note that there is a hole just to the left of
         each byte, with an extra at the end:

    总结: 1. strchr查找是以循环比较所查找字符

        2. 字符 char默认是 1 个字节,若是宽字符则需令处理

  • 相关阅读:
    软件测试课堂练习1
    安卓增删改查
    安卓数据库表
    安卓注册登录
    安卓购物清单
    安卓计算器
    第四周安卓作业
    第七周作业
    jsp第六周
    第四次jsp作业
  • 原文地址:https://www.cnblogs.com/iclk/p/4279118.html
Copyright © 2011-2022 走看看