6.3sizeof和strlen在字符计算中的区别
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
/* 6.3
author:edcfreedom
date:2021/8/19
funDescription:
计算字符串中字符的个数
sizeof和strlen的区别
不能用sizeof来计算字符串中有效字符的个数!!!应该要用strlen,它在计算字符串大小的时候,遇到'\0'后,就结束技术了
such as:hello\0world 到\0就结束了
*/
/*
问题:
网络通信,获取的消息有乱码
协议,两端不匹配
*/
int main()
{
int a[] = {1,2,3};
printf("%d\n",sizeof(a)/sizeof(a[0]));
char a2[] = "hello";
printf("%d\n",sizeof(a2)/sizeof(a2[0]));
printf("我们希望得到hello的真实字母个数,用strlen,结果为:%d\n",strlen(a2));
return 0;
}