C语言哪个函数可以测定字符串的长度
7个回答
2018-02-12
展开全部
用sizeof函数,得到字节大小,然后看这个数组什么类型的,比如double类型,一个就占16位,就是2字节,就算出来了。
c++直接有length函数,可以直接给出长度,c没有
满意请采纳,如有疑问请追问
c++直接有length函数,可以直接给出长度,c没有
满意请采纳,如有疑问请追问
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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 );
/* 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 );
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int strlen(const char *s) ,s为待求长度的字符串指针,头文件string.h
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
头文件string.h
strlen(char str[]) ,str[]为待求长度的字符串
strlen(char str[]) ,str[]为待求长度的字符串
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询