Sizeof vs. Strlen [英] Sizeof vs. Strlen

查看:81
本文介绍了Sizeof vs. Strlen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想起来,因为我们可以得到任何给定字符串文字S和''sizeof S-1'的任何

的长度,那么,什么是优点

库函数strlen()的存在?提前为你的

指令。

it just came up my mind that since we can get the length of any
given string literal S with ''sizeof S-1'', so, what''s the merit of
library function strlen()''s existence ? thanx in advance for your
instruction.

推荐答案

sugaray写道:
sugaray wrote:
它我想起了因为我们可以得到任何给定字符串文字S的长度为''sizeof S-1'',所以,
库函数strlen()的优点是什么? '存在?提前完成你的
指示。
it just came up my mind that since we can get the length of any
given string literal S with ''sizeof S-1'', so, what''s the merit of
library function strlen()''s existence ? thanx in advance for your
instruction.




#include< stdio.h>

#include< string.h> ;


int main(无效)

{

char s [20] =" hello";

char * ptr =" hello2";


printf(" s:sizeof ==%u,strlen ==%u \ n",sizeof s, strlen(s));

printf(" ptr:sizeof ==%u,strlen ==%u \ n",sizeof ptr,strlen(ptr));


返回0;

}


-

Thomas。


在< ad ************************** @ posting.google.com> ru****@sohu.com (sugaray)写道:
In <ad**************************@posting.google.com > ru****@sohu.com (sugaray) writes:
它只是出现在我的脑海中,因为我们可以得到任何给定字符串文字S的长度为''sizeof S-1'',那么,
库函数strlen的优点是什么( )存在吗?提前用于你的
指令。
it just came up my mind that since we can get the length of any
given string literal S with ''sizeof S-1'', so, what''s the merit of
library function strlen()''s existence ? thanx in advance for your
instruction.




strlen很少用字符串文字作为参数...


Dan

-

Dan Pop

DESY Zeuthen,RZ集团

电子邮件: Da ***** @ ifh.de


2004年5月27日05 :52:29 -0700,在comp.lang.c中, ru****@sohu.com (sugaray)

写道:
On 27 May 2004 05:52:29 -0700, in comp.lang.c , ru****@sohu.com (sugaray)
wrote:
它只是出现在我脑海中,因为我们可以得到任何给定字符串文字S的长度''sizeof S -1'',


你不需要-1

所以,
库函数strlen的优点是什么()存在吗?提前完成你的
指示。
it just came up my mind that since we can get the length of any
given string literal S with ''sizeof S-1'',
you don''t need the -1
so, what''s the merit of
library function strlen()''s existence ? thanx in advance for your
instruction.




#include< stdio.h>

#include< stdlib.h>

#include< string.h>


int main(无效)

{

char * somestr =" hello world";

printf(" length is%d或%d \ n",sizeof somestr,strlen(somestr));

return EXIT_SUCCESS;

}


-

Mark McIntyre

CLC FAQ< http:/ /www.eskimo.com/~scs/C-faq/top.html>

CLC自述文件:< http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>

---- ==通过Newsfeed.Com发布 - 无限制 - 未经审查 - 安全Usenet新闻== ----
http://www.newsfeed.com 世界排名第一的新闻组服务! > 100,000新闻组

--- = 19东/西海岸专业服务器 - 通过加密的总隐私= ---

---- ==通过新闻发布.Com - Unlimited-Uncensored-Secure Usenet News == ----
http:// www.newsfeed.com 世界排名第一的新闻组服务! > 100,000新闻组

--- = 19东/西海岸专业服务器 - 通过加密的总隐私= ---



#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
char* somestr = "hello world";
printf("length is %d or %d\n", sizeof somestr, strlen(somestr));
return EXIT_SUCCESS;
}

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


这篇关于Sizeof vs. Strlen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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