Trying to find a way to create an array with a type that can store a string with numbers and leters in it. char doent work for that.
The array must be like the following. Array doesn't need to be modified.
If there is no way for that which data structure should be used?
Thanks for the answers.
`int main(void)
{
char parsing_table[12][9] = {{'0','0','0','0','0','0','0','0','0'},
{'0','0','0','0','0','0','0','0','1'},
{'0','0','0','0','S6','0','0','0','0'},
{'0','0','0','0','0','R3','0','0','0'},
{'0','R3','0','0','0','0','accept','0','0'},
{'0','0','0','0','0','0','0','0','0'},
{'0','0','0','0','0','R1','0','4','0'},
{'0','0','S11','0','0','0','0','0','5'},
{'0','0','0','0','S8','0','0','0','0'},
{'0','R5','0','0','0','0','0','1','0'},
{'0','0','0','0','0','0','0','0','0'},
{'0','0','0','0','0','0','0','2','0'},};
for(int i = 0; i < 12; i )
{
for (int j = 0; j < 9; j )
{
printf("%c ", parsing_table[i][j]);
}
puts("");
}
}`
CodePudding user response:
You can use array of pointers to char
:
char *arr[3][2] =
{
{"R2", "S3"},
{"Z3", "D3"},
{"Y4", "B3"},
};
Or array of strings
char arr1[3][2][3] =
{
{"R2", "S3"},
{"Z3", "D3"},
{"Y4", "B3"},
};
EDIT:
for(size_t row = 0; row < 2; row )
{
for (size_t col = 0; col < 3; col )
{
printf("%s ", arr[row][col]);
//or
//printf("%s ", arr1[row][col])
}
puts("");
}