内置函数 strlen

 1 //内置函数   strlen
 2 //计算字符串的实际长度,不含字符串结束标准\0
 3 
 4 #include<stdio.h>
 5 #include<stdlib.h>
 6 #include<string.h>
 7 
 8 void main()
 9 {
10 
11     char words1[] = {'z','h','e','n','g','l','e','i','\0'};
12     char words2[] = "zhenglei";
13     char words3[] = "你好,zero!";  //一个中文字符占两个字节
14 
15     printf("words1长度为:%d\n",strlen(words1));
16     printf("words2长度为:%d\n",strlen(words2));
17     printf("words3长度为:%d\n",strlen(words3));
18 }

 

posted on 2021-07-28 09:30  Bytezero!  阅读(57)  评论(0编辑  收藏  举报