mstrnlen.c
来自「与C语言四书五经之《C和指针》的配套的书上源代码。」· C语言 代码 · 共 21 行
C
21 行
/*
** Safe string length. Returns the length of a string that
** is possibly not NUL-terminated. 'size' is the length of the
** buffer in which this string is stored.
*/
#include <string.h>
#include <stddef.h>
size_t
my_strnlen( char const *string, int size )
{
register size_t length;
for( length = 0; length < size; length += 1 )
if( *string++ == '\0' )
break;
return length;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?