C语言:写一个函数求字符串长度

#include
#include
size_t my_strlen(const char* str) {
	assert(str);
	size_t count = 0;
	while (*str!='\0') {
		str++;
		count++;
	}
	return count;
}
int main() {
	char arr[] = "abcdef";
	size_t n = my_strlen(arr);
	printf("%u\n", n);
}

运行结果

你可能感兴趣的:(c语言,算法,开发语言)