常用的字符串处理函数
字符串处理类
strlen
简单介绍
size_t strlen ( const char * str );
Geting string length.
参数:str,返回值:字符串长度
字符串以\0
作为结束标志,返回\0
之前的字符个数。返回值是size_t
(无符号)。
模拟实现
1 | //方法1:计时器 |
strcpy
简单介绍
char * strcpy ( char * destination, const char * source );
Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point).
以\0
结束,且将\0
拷贝到目标空间
模拟实现
1 | char* My_strcpy(char* des, char* src) { |
strcat
简单介绍
char * strcat ( char * destination, const char * source );
Concatenate strings.
模拟实现
1 | char* My_strcat(char* des, char* src) { |
strcmp
简单介绍
int strcmp ( const char * str1, const char * str2 );
Compare two strings.
模拟实现
1 | int My_strcmp(const char* str1, const char* str2) { |
strstr
简单介绍
const char * strstr ( const char * str1, const char * str2 );
模拟实现
1 | const char* My_strstr(const char* str1, const char* str2) { |
内存操作类
memcpy
简单介绍
void * memcpy ( void * destination, const void * source, size_t num );
Copy block of memory.
模拟实现
1 | void* My_memcpy(void* des, void* src, size_t count) { |
memmove
简单介绍
void * memmove ( void * destination, const void * source, size_t num );
Move block of memory,allowing the destination and source to overlap.
模拟实现
1 | void* My_memmove(void* des, void* src, size_t count) { |