c語言string長度
❶ 在c語言中怎麼輸出一個字元串的長度是多少
charstr[]="123";
strlen(str)這個就求出長度了
然後printf("len[%d]",strlen(str));就輸出了這個字元串的長度
❷ c語言求字元串長度
C語言中字元串長度的函數是strlen(),一個字元的長度為1;
函數原型:
unsigned int strlen (char *s);頭文件:
#include <string.h>參數說明:s為指定的字元串;
功能說明:strlen()用來計算指定的字元串s 的長度,不包括結束字元'\0';
返回值:返回字元串s 的字元數;
注意:strlen() 函數計算的是字元串的實際長度,遇到第一個'\0'結束。
示例:
#include<stdio.h>#include<string.h>int main(){ char str[] = "ab\nxyz";//\n為回車字元,佔一個位元組 printf("strlen(str)=%d\n", strlen(str)); return 0;}//輸出結果:strlen(str)=6 收起
❸ c語言如何求字元串長度
我的方法和樓上的大同小異用指針法:#include "stdio.h"
void main()
{char str[128];<br> char * p;<br> int count=0;<br> p=str;<br> gets(str);<br> while(*p++!='\0')<br> count++;<br> printf("%d",count);<br>}非指針法(這個方法是調用系統函數,比之自己寫的函數簡單明了):#include "stdio.h"
#include "string.h"
void main()
{char str[128];<br> gets(str);<br> printf("%d",strlen(str));<br> }
❹ c語言 計算字元串長度
C語言的字元串是由字元數組形式保存的,並約定'