欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在C语言中编写一个函数来计算字符串的长度

最编程 2024-02-15 18:45:19
...
#include<stdio.h>
#include<assert.h>
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);
}

运行结果

推荐阅读