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