array of chars from array of array of chars

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

array of chars from array of array of chars

ソリューションへジャンプ
811件の閲覧回数
GMVS
Contributor III

hello

 

i got a bidimensional array of chars

 

assume it looks like this

 

const char array[3][17]={"mary",

                                      "has a",

                                      "lamb"};

 

1) can i safely assume the matrix is gonna end like this?

 

012 345678910111213141516
mary/0
has0x20a/0
lamb/0

 

 

assume i have a function like this

void function(char something[]);

 

2) is there any easy way to send just the second row of array to the function??

because if i write

 

function(array[1][0]);

 

this thing is gonna break

 

3) or should i make a new unidimensional array, copy the info from the other to this one with a for cycle and then send it?

 

thanks

 

edited by: GM VS syntaxis

ラベル(1)
0 件の賞賛
返信
1 解決策
667件の閲覧回数
bigmac
Specialist III

Hello,

1. When initialising the array, the individual strings will need to be separated using commas, and the array definition should end with a semicolon.
char array[3][17] = {"mary",  "has a", "lamb" };

If you are expecting the array data to be located within flash memory, you will need to use the const modifier.

2. The function is expecting a pointer to the first element of a single dimension array.  To send the second element of the two-dimenional array to the function you can use array[1] as the parameter.  This should give identical results to the alternative &array[1[[0].

Regards,

Mac

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
668件の閲覧回数
bigmac
Specialist III

Hello,

1. When initialising the array, the individual strings will need to be separated using commas, and the array definition should end with a semicolon.
char array[3][17] = {"mary",  "has a", "lamb" };

If you are expecting the array data to be located within flash memory, you will need to use the const modifier.

2. The function is expecting a pointer to the first element of a single dimension array.  To send the second element of the two-dimenional array to the function you can use array[1] as the parameter.  This should give identical results to the alternative &array[1[[0].

Regards,

Mac

0 件の賞賛
返信
667件の閲覧回数
GMVS
Contributor III

yey!

thanks a lot

if i had to make fors for every time i want to use the routine i was gonna waste a hell of time

:smileylaugh:

0 件の賞賛
返信