将结构矩阵传递给函数 [英] Passing a matrix of structs to a function

查看:48
本文介绍了将结构矩阵传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将矩阵传递给另一个文件中的函数以执行某些操作?我分配了包含如下结构的矩阵:

How can I pass my matrix to a function in another file to do something? I allocated my matrix containing structs like this:

   typedef struct {
        int x;
        int y;
        int z;
    } myStruct;
    
    myStruct(*matrix)[COL] = malloc(ROW*sizeof*matrix);

推荐答案

矩阵是一个数组数组,因此您也可以使用指向 mystruct 的指针.行和列,以便函数知道如何处理它:

A matrix is an array of arrays, so you could use a pointer to a pointer to mystruct, as well and the number of rows and columns so the function knows how to handle it:

void myfunction(mystruct** matrix, int rows, int columns) {
    // Your logic goes here...
}

这篇关于将结构矩阵传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆