C语言哪个函数可以测定字符串的长度

如题所述

C语言中,计算字符串长度的函数为strlen。
1 形式:
int strlen(const char *s);
2 头文件:
string.h
3 功能:
计算字符串s的长度,并返回。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-02-12
用sizeof函数,得到字节大小,然后看这个数组什么类型的,比如double类型,一个就占16位,就是2字节,就算出来了。
c++直接有length函数,可以直接给出长度,c没有
满意请采纳,如有疑问请追问
第2个回答  推荐于2016-06-09
Example
/* STRLEN.C */

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>

void main( void )
{
char buffer[61] = "How long am I?";
int len;
len = strlen( buffer );
printf( "'%s' is %d characters long\n", buffer, len );
}

Output
'How long am I?' is 14 characters long

/////////////////////////////////////////////////////////

CString::GetLength
int GetLength( ) const;

Return Value

A count of the bytes in the string.

Remarks

Call this member function to get a count of the bytes in this CString object. The count does not include a null terminator.

For multibyte character sets (MBCS), GetLength counts each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two bytes.

Example

The following example demonstrates the use of CString::GetLength.

// example for CString::GetLength
CString s( "abcdef" );
ASSERT( s.GetLength() == 6 );本回答被提问者采纳
第3个回答  2006-09-27
int strlen(const char *s) ,s为待求长度的字符串指针,头文件string.h
第4个回答  2006-09-28
头文件string.h
strlen(char str[]) ,str[]为待求长度的字符串