确定多维数组中的行大小和列大小

埃德温·普拉特(Edwin Pratt)

如何确定的尺寸在C 2维阵列的++时每行和列大小可以变化?

我正在尝试制作一个称为Parser读取数组的函数到目前为止,我有:

// Function:    Parser.
// Description: First, it reads the data in the array.
//              Then, it uses the data in the array.
void Parser (char ch[][]) {
    for (int i = 0; i < (sizeof (ch) / sizeof (ch [0])); ++i) {
        // TO DO - Add content.
    }
}

数组ch可以包含以下元素:

{
    {
        'v', 'o', 'i', 'd'
    },

    {
        'i', 'n', 't'
    },
}

有解决方案吗?

埃德温·普拉特(Edwin Pratt)

我所做的是,制作ch了一个vector在第一个循环中将chsize传递给了迭代器,然后i将其传递给了iterator forch[i]j


新的代码是:

// Function:    Parser.
// Description: First, it reads the data in the vector.
//              Then, it uses the data in the vector.
void Parser (vector <vector <char>> ch) {
    for (int i = 0; i < ch.size (); ++i) {
        for (int j = 0; j < ch[i].size (); ++j) {
            // TO DO - Add content.
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章