strlen计算字符串长度


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

 

int main01()

{

//计算字符串有效个数

  char ch[100]="hello world";

  printf("数组大小:%d\n",sizeof(ch));//100

//strlen头文件为<string.h>;计算计算字符个数,包括空格,不包括'\0'

  printf("字符串长度:%d\n",strlen(ch))//11

  return 0;

}

 

int main02()

{

  char ch[100]="hello world";

  int len =0;

  while(ch[len]!='\0'

  {

    len++;

  }

  printf("字符串长度:%d\n",len);//11

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM