c - 这个代码是不是不正确?

标签 c pointers matrix copy memcpy

我的导师展示了这个 slide对于“矩阵复制”:

#define ROWSIZ 17
#define COLSIZ 27
int enamatrisen[ROWSIZ][COLSIZ];
int andramatrisen[ROWSIZ][COLSIZ];

void matcpy (int* dst, int* src)
{
  int i, j;
  for (i=0; i<ROWSIZ, i=i+1)   /* rad-nr */
   for (j=0; j<COLSIZ, j=j+1)  /* kolumn-nr */
    dst[i][j] = src[i][j];
}

但是

1) 说的地方有bug,应该是;

2) 代码无法编译。 gcc 提示指针被用作数组或类似的东西。什么是正确的代码?这项工作进展如何?不应该为此使用 memcpy 还是这是为了实现类似 memcpy 的努力?

最佳答案

函数参数定义错误。

有关传递多维数组的更多信息: http://www.eskimo.com/~scs/cclass/int/sx9a.html

此外,for 循环中的逗号应该是分号。

void matcpy(int dst[][COLSIZ], int src[][COLSIZ])
{
    int i, j;
    for (i = 0; i < ROWSIZ; i = i + 1)   /* rad-nr */
        for (j = 0; j < COLSIZ; j = j + 1)  /* kolumn-nr */
            dst[i][j] = src[i][j];
}

void matcpy(int (*dst)[COLSIZ], int (*src)[COLSIZ])
{ 
    int i, j;
    for (i = 0; i < ROWSIZ; i = i + 1)   /* rad-nr */
       for (j = 0; j < COLSIZ; j = j + 1)  /* kolumn-nr */
           dst[i][j] = src[i][j];
}

关于c - 这个代码是不是不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12813135/

相关文章:

c - bpkt ARM 指令卡住了我的嵌入式应用程序

arrays - 读取文件并在 C 中打印内容

c++ - 一个好的数学 vector/矩阵类/结构可以为 C++ 下载?

c - 下三角矩阵和上三角矩阵给了我错误的答案

c++ - 我如何保持打开控制台?

c++ - 代码阻止调试器无法启动

c - 修改通过引用传递的指针

c - 指针递增时 'free' 是如何工作的

java - 用改变 StopX 和 StopY 的位图画线

c - 错误 : expected declaration specifiers or ‘...’ before ‘list_node’