C: Size of two dimensional array

后端 未结 5 1868
无人共我
无人共我 2021-02-12 09:37

I need some help counting the rows and columns of a two dimensional array. It seems like I can\'t count columns?

#include 

int main() {

char res         


        
5条回答
  •  被撕碎了的回忆
    2021-02-12 10:17

    That's a problem of integer division!

    int column = sizeof(result[0])/row;
    

    should be

    int column = 7 / 10;
    

    and in integer division, 7/10==0.

    What you want to do is divide the length of one row, eg. sizeof(result[0]) by the size of one element of that row, eg. sizeof(result[0][0]):

    int column = sizeof(result[0])/sizeof(result[0][0]);
    

提交回复
热议问题