b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

strstr函数的用法_c find函数返回值_strchr函数(5)

电脑杂谈  发布时间:2017-01-31 04:07:50  来源:网络整理

如果存在,则返回第一次查找到的字节地址,

不存在,则返回空*/

   pRetval = strrchr((char*)pSrc, 98);
    printf("[%s]-[%d] pRetval = %s \n", __func__, __LINE__, pRetval);

/* 个人理解:在目标字符串中,从字符串开头开始查找对已ASCII码为98的字节,

如果存在,则返回最后一次查找到的字节地址,

不存在,则返回空*/

    return 0;
}
~     
4 strcoll 比较字符串

int main (void )
{
    /* 
     * like the strcmp  
     */
    return 0;
} 
~                                                                                                                                                                                
~    

5 strdup

类与字符串拷贝函数,只是需要手动释放返回的字符串地址

int main (void )
{

/* NAME

strdup, strndup - duplicate a string

* SYNOPSIS

#include <string.h>

char *strdup(const char *s);

char *strndup(const char *s, size_t n);

* DESCRIPTION

The strdup() function returns a pointer to a new string which is a duplicate of the string s.

Memory for the new string is obtained with malloc(3), and can be freed with free(3).

The strndup() function is similar, but only copies at most n characters.

If s is longer than n, only n characters are copied, and a terminating null byte ('\0') is added.

* RETURN VALUE

The strdup() function returns a pointer to the duplicated string, or NULL if insufficient memory was available.

*/

 const char *pSrc = "Hello, world!";
    
    char *pRetval = strdup( pSrc );
    printf("[%s]-[%d] pRetval = %s \n", __func__, __LINE__, pRetval);
    /* 复制目标字符串,返回字符串的内存地址需要自己手动释放 */  
    if( pRetval != NULL )
    {
        free( pRetval );
        pRetval = NULL;
    }
    
    pRetval = strndup( pSrc, 4);
    /* 复制指定长度目标字符串,返回字符串的内存地址需要自己手动释放 */  
    printf("[%s]-[%d] pRetval = %s \n", __func__, __LINE__, pRetval);
    if( pRetval != NULL )
    {
        free( pRetval );
        pRetval = NULL;
    }
    
    return 0;
}


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-29692-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 陈冲
      陈冲

      果断刷机了

    • 肖淇
      肖淇

      所谓“日本潜艇强于中国”的说法完全是无稽之谈

      • 河本明子
        河本明子

        在这里你说关你鸟事

    热点图片
    拼命载入中...