字符串类型

字符串类型

learn/c

想什么呢,C 语言中没有字符串类型

自定义计算字符串类型数组长度

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<string.h>
引入对应的头文件
int my_strlen(char* str){
int count = 0;
while(*str != '\0'){
count++;
str++;
}
return count;
}
int main(){
int len = my_strlen("abcdefg");
printf("%d\n" , len);
return 0;
}