matrix.c
来自「spiht的压缩解压缩c编写的」· C语言 代码 · 共 60 行
C
60 行
#include "spiht.h"
#include "spihtdecode.h"
QccMatrix QccMatrixAlloc(int num_rows, int num_cols)
{
QccMatrix matrix;
int row;
if ((num_rows <= 0) || (num_cols <= 0))
return(NULL);
if ((matrix =
(QccMatrix)malloc(sizeof(QccVector)*num_rows)) == NULL)
{
QccErrorAddMessage("(QccMatrixAlloc): Error allocating memory");
return(NULL);
}
for (row = 0; row < num_rows; row++)
if ((matrix[row] = QccVectorAlloc(num_cols)) == NULL)
{
QccErrorAddMessage("(QccMatrixAlloc): Error allocating memory");
free(matrix);
return(NULL);
}
return(matrix);
}
void QccMatrixFree(QccMatrix matrix, int num_rows)
{
int row;
if (matrix != NULL)
{
for (row = 0; row < num_rows; row++)
QccVectorFree(matrix[row]);
free(matrix);
}
}
int QccMatrixCopy(QccMatrix matrix1, const QccMatrix matrix2,
int num_rows, int num_cols)
{
int row, col;
if ((matrix1 == NULL) ||
(matrix2 == NULL) ||
(num_rows <= 0) ||
(num_cols <= 0))
return(0);
for (row = 0; row < num_rows; row++)
for (col = 0; col < num_cols; col++)
matrix1[row][col] = matrix2[row][col];
return(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?