C 将屏幕坐标转换为阵列栅格坐标

C 将屏幕坐标转换为阵列栅格坐标,c,arrays,coordinates,C,Arrays,Coordinates,我正在使用ANSIC,希望将屏幕上的borland图形坐标,即(35134)转换为(0,0)的栅格坐标。我的网格创建功能如下: void createGrid(int ***a, int m, int n) { int i,j,color=0; *a=(int**)malloc(sizeof(int)*n); //reserves memory for n for(i=0;i<n;i++){ //external loop *(*a+i

我正在使用ANSIC,希望将屏幕上的borland图形坐标,即(35134)转换为(0,0)的栅格坐标。我的网格创建功能如下:

void createGrid(int ***a, int m, int n)
{
    int i,j,color=0;

    *a=(int**)malloc(sizeof(int)*n);    //reserves memory for n

    for(i=0;i<n;i++){   //external loop
        *(*a+i)=(int*)malloc(sizeof(int)*m);    //reserves memory for m
    if(a){
         for(j=0;j<m;j++){ //internal loop
            *(*(*a+i)+j)=color;
            }
        }
    }
}
void createGrid(int***a,int m,int n)
{
int i,j,color=0;
*a=(int**)malloc(sizeof(int)*n);//为n保留内存

对于(i=0;i嗯,经过大量的阅读和探索,我发现这个难题的答案是取(0后空格的坐标数)/单元格的大小/10=2。此公式适用于x和y坐标,用于将它们转换为二维数组的i&j索引。

第一个
sizeof(int)
不应该是
sizeof(int*)
?并且请尽量避免成为a。此外(尽管此处宽度=高度=30)无法从参数名
m
n
判断哪个是哪个。欢迎使用StackOverflow。请制作一个。MCVE应包括各种示例输入(说明所有方面)和所需的输出。如果您正在寻找有关调试代码的帮助,请参阅m=30,n=30每个单元格的大小为10个单位。我计算出x为(索引*单元格大小)+32,其中32是坐标(32131)中的第一个x,(2*10)+32=52。52是(2,0)的网格x坐标…不幸的是,我一直无法算出y的公式。@Weather Vane,你完全正确!感谢你在int*方面指出这一点。我不想成为一名三星级程序员,但我遵循教授的意愿。。。