天天看点

C语言模拟实现库函数strlen

#include<stdio.h>
#include<assert.h>

int my_strlen(const char* arr)
{
	assert(arr != NULL);
	int count = 0;
	while (*(arr++))
	{
		count++;
	}
	return count;
}

int main()
{
	char arr[] = "hellobit";
	int ret = my_strlen(arr);
	printf("%d\n", ret);
	return 0;
}
           

输出结果:

C语言模拟实现库函数strlen

继续阅读