strlen的

编程入门 行业动态 更新时间:2024-10-26 04:26:47
本文介绍了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>在消息中写道 news:cf ********** @ ns1.fe.internet.bosch ... "Imran" <im******@in.bosch> wrote in message news:cf**********@ns1.fe.internet.bosch... 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>在消息新闻中写道:< cf ********** @ ns1.fe.internet.bosch> ... "Imran" <im******@in.bosch> wrote in message news:<cf**********@ns1.fe.internet.bosch>... 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的

本文发布于:2023-07-30 00:43:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1245037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:strlen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!