C: Size of two dimensional array

后端 未结 5 884
余生分开走
余生分开走 2021-02-12 09:23

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:20

    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]);
    

提交回复
热议问题