如何初始化在C多维字符数组? [英] How to Initialize a Multidimensional Char Array in C?
问题描述
我想从C#转换某些code到C,以便它可以被刻录到微控制器。
可能有人请告诉我,我怎么会在C#中的二维字符串数组转换成的东西用C?
我的C#code是这样的:
字符串[,] DirectionPosition = {{00,10,,01,},
{01,11,,02,00},
{02,12,,03,01},
{03,13,,04,02},
{04,14,,,03},
{10,20,00,11,},
{11,21,01,12,10},
{12,22,02,13,11},
。
。
。
。
{44,,34,,43},};
而且,我将如何访问元素?
在C#中,如果我在第三排想要的第二个元素,将仅仅是DirectionPosition [2,1],但究竟是什么,等效时,有C中没有字符串要少得多的2-D字符串数组?
字符DirectionPosition [] [5] [3] = {{00,10,, 01,},
{01,11,,02,00},
{02,12,,03,01},
{03,13,,04,02},
{04,14,,,03},
{10,20,00,11,},
{11,21,01,12,10},
{12,22,02,13,11},
。
。
。
。
{44,,34,,43},};
C有没有内置的字符串类,你必须凑合用字符数组。你可以选择使用指针指向char。
I'm trying to convert some code from C# to C so that it can be burnt onto a microcontroller.
Could someone please tell me how I would convert a two dimensional string array in C# into something in C?
My C# code looks like this:
string[,] DirectionPosition = {{"00", "10", "", "01", ""},
{"01", "11", "", "02", "00"},
{"02", "12", "", "03", "01"},
{"03", "13", "", "04", "02"},
{"04", "14", "", "", "03"},
{"10", "20", "00", "11", ""},
{"11", "21", "01", "12", "10"},
{"12", "22", "02", "13", "11"},
.
.
.
.
{"44", "", "34", "", "43"},};
And moreover, how would I access the elements? In C# if I wanted the second element in the third row it would simply be DirectionPosition[2,1] but what is the equivalent of that when there is no string in C much less 2-D string arrays?
char DirectionPosition[][ 5 ][ 3 ] = {{"00", "10", "", "01", ""},
{"01", "11", "", "02", "00"},
{"02", "12", "", "03", "01"},
{"03", "13", "", "04", "02"},
{"04", "14", "", "", "03"},
{"10", "20", "00", "11", ""},
{"11", "21", "01", "12", "10"},
{"12", "22", "02", "13", "11"},
.
.
.
.
{"44", "", "34", "", "43"},};
C has no inbuilt string class, you have to make do with character arrays. You could alternatively use pointers to pointer to char.
这篇关于如何初始化在C多维字符数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!