How to initialize a multidimensional Char array in C?

I am trying to convert code from C # to C so that it can be burned on a microcontroller.

Can someone please tell me how I would convert a two-dimensional array of strings in C # to something in C?

My C # code is as follows:

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 besides, how can I access the elements? In C #, if I needed the second element in the third line, it would just be DirectionPosition [2,1], but what is equivalent to the fact that when in C there is no line with much smaller 2-line lines?

+3
source share
4 answers
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 , . char.

+7

char :

char *DirectionPosition[9][5] = {
    {"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"}
};

"10" DirectionPosition[0][1] (, - , - ).

+10

, :

typedef char string[3];
typedef string s5[5];

    s5 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"},};

DirectionPosition [2] [1] & c .

+2

:

#include <stdio.h>

int main(int argc, char **argv) {

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"};

    printf("dp[1][1] == %s\n", DirectionPosition[1][1]);
    printf("dp[1][2] == %s\n", DirectionPosition[1][2]);
    printf("dp[1][3] == %s\n", DirectionPosition[1][3]);

    return;
}
+1

Source: https://habr.com/ru/post/1708028/


All Articles