strlen是如何实现的? [英] How is strlen implemented?

查看:156
本文介绍了strlen是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道如何实现strlen。

如果输入字符串没有空终止符,即

''\ 0''?

非常感谢

Roy

Hi,

I was wondering how strlen is implemented.
What if the input string doesn''t have a null terminator, namely the
''\0''?
Thanks a lot
Roy

推荐答案

" roy" < RO ***** @ hotmail.com>写道:
"roy" <ro*****@hotmail.com> writes:

我想知道如何实现strlen。
如果输入字符串没有空终止符,即
''\'''?
Hi, I was wondering how strlen is implemented.
What if the input string doesn''t have a null terminator, namely the
''\0''?




没有空字节终止符,它不是字符串!

strlen ()然后可以做任何想做的事。


-

克里斯。



Without the null-byte terminator, it''s not a string!
strlen() can then do whatever it wants.

--
Chris.


谢谢。也许我的问题应该是如果输入是一个char数组

没有空终止符。但是根据我的实验结果,似乎

strlen仍然可以返回char数组的字符数。

我只是不确定我是幸运还是......其他事情发生在

strlen。

Thanks. Maybe my question should be "what if the input is a char array
without a null terminator". But from my experimental results, it seems
that strlen can still return the number of characters of a char array.
I am just not sure whether I am just lucky or sth else happened inside
strlen.




roy写道:

roy wrote:


我想知道如何实现strlen。
如果输入字符串没有空终止符,即
''\ 0''怎么办? ?
非常感谢
Roy
Hi,

I was wondering how strlen is implemented.
What if the input string doesn''t have a null terminator, namely the
''\0''?
Thanks a lot
Roy



strlen会从char *中读取,直到找到''\0''字符。如果您的

字符串不使用''\ 0''作为终结符,那么您应该避免使用

< string.h>功能。


-Jason



strlen will read from the char* until it finds a ''\0'' char. If your
string does not use the ''\0'' as a terminator, then you should avoid
most of the <string.h> functions.

-Jason


这篇关于strlen是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆