strlen的 [英] strlen

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

问题描述

Hello All


我有一个2D数组,

char arr [4] [10] = {" Hello", world,test,hi};


如何找到数组的strlen


我期待数组长度为4


感谢Adv

Hello All

I have a 2D array,

char arr[4][10] = {"Hello","world","test","hi"};

how can find the strlen of the array

am expecting array length as "4"

Thanks in Adv

推荐答案

" Imran" < IM ****** @ in.bosch.com>在消息中写道

news:cf ********** @ ns1.fe.internet.bosch.com ...
"Imran" <im******@in.bosch.com> wrote in message
news:cf**********@ns1.fe.internet.bosch.com...
Hello All

我有一个2D数组,


如何找到阵列的strlen

我希望数组长度为4

感谢Adv
Hello All

I have a 2D array,

char arr[4][10] = {"Hello","world","test","hi"};

how can find the strlen of the array

am expecting array length as "4"

Thanks in Adv




您的预期答案表明您确实在尝试确定多维数组的第一个维度。 strlen函数没有这样做。
这样做。在什么情况下你想确定这个?如果你在函数内部是
,那么你可能必须将第一个维度传递给

函数。例如:


void foo(char(* arr)[10],int size){

for(int i = 0; i< size ; ++ i){

std :: cout<< arr [i]<< std :: endl;

}

}


int main(){

char arr [4] [10] = {" Hello",world,test,hi};

foo(arr,sizeof(arr)/ sizeof(arr [ 0]));

返回0;

}


-

David Hilsee



Your expected answer indicates that you are really trying to determine the
first dimension of a multi-dimensional array. The strlen function does not
do this. In what context are you trying to determine this? If you''re
inside a function, then you may have to pass the first dimension to that
function. For example:

void foo(char (*arr)[10], int size) {
for ( int i = 0; i < size; ++i ) {
std::cout << arr[i] << std::endl;
}
}

int main() {
char arr[4][10] = {"Hello","world","test","hi"};
foo(arr,sizeof(arr)/sizeof(arr[0]));
return 0;
}

--
David Hilsee


" Imran" < IM ****** @ in.bosch.com>在消息新闻中写道:< cf ********** @ ns1.fe.internet.bosch.com> ...
"Imran" <im******@in.bosch.com> wrote in message news:<cf**********@ns1.fe.internet.bosch.com>...
Hello All

我有一个2D数组,

char arr [4] [10] = {" Hello",world,test,hi};
<如何找到数组的strlen

我希望数组长度为4
Hello All

I have a 2D array,

char arr[4][10] = {"Hello","world","test","hi"};

how can find the strlen of the array

am expecting array length as "4"




当你''时有一种可能性真正使用数组(即不是一个

指针)就像:


#define elements(x)((sizeof(x)/ sizeof (x [0]))

请记住,数组会随时衰减到指针

它作为参数传递,所以这实际上只能应用于
全局,或者在定义数组的函数内部。


-

后来,

杰瑞。


宇宙是自己想象的虚构。



One possibility when you''re truly working with an array (i.e. NOT a
pointer) is something like:

#define elements(x) ((sizeof(x)/sizeof(x[0]))

Keep in mind, however, that an array will decay to a pointer anytime
it is passed as a parameter, so this can really only be applied to
globals, or else inside of the function where the array is defined.

--
Later,
Jerry.

The universe is a figment of its own imagination.


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

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