Tag: grid

c – 在2d数组中检查null

我从输入文件中填充10 x 10个字符的网格。 我需要检查网格是否是正方形(即,有N×N个字符,其中N <= 10) 输入文件是这样的: pitk olpe pkey tope 当我在gdb中打印网格时,我得到以下结果: $1 = {“pitk\000\000\000\000\366h”, “olpe\000\000\001\000\000”, “pkey\000\000\000\000\000”, “tope\000\000\000\000\000”, “\000\344\241\367\377\177\000\000”, , “\000\377\377\177\000\000\037\355\336”, , “\000\177\000\000\000\000\000\000\000”, “\000\000\000\000\000\000\000\000\000”, “\000\000\000\000\000\000\000\000\r\020”, “\000\000\000\000\000\000\000\000\000”} 我的主函数中检查网格是否有效的部分是: bool check = (checknxn(grid)); if(check == false) { fprintf(stderr, “Invalid Input!\n”); exit(0); } checknxn函数: bool checknxn(char grid[10][10]) { int columns = 0; for(int i=0;i<10;i++) { if(grid[0][i]!=NULL) columns++; else […]