内置函数 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 }
本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15072462.html