代码训练
模拟实现strlen
#include <stdio.h>
#include <assert.h>
size_t my_strlen(const char* stc)//size_t=unsigned int(无符号整型)
{
assert(stc);//断言,注意要引头文件<assert.h>
int count = 0;
while (*(stc++))//\0=0,所以当到\0时退出循环
{
count++;
}
return count;
}
int main()
{
char arr[] = "abcdef";//="abcdef\0"
int n = my_strlen(arr);
printf("%d", n);
return 0;
}