需要帮助返回或通过引用二维数组传递 [英] need help returning or passing by reference a 2-d array

查看:70
本文介绍了需要帮助返回或通过引用二维数组传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是c的新手,来自Java背景。我正在研究一个数学程序,我有一个需要返回二维数组的函数。经过一些网络搜索后,我确定在c中,最好只传递函数中的数组。由于数组是通过引用传递的,我希望更新的数组能够以填充的正确值传回,但是,从数据库返回后,只返回数组的第一行(其余行用零填充)功能。我知道值正在填写,因为我在从函数返回之前验证了(填充数组)。对不起,很长的帖子,只是想解释一下情况。下面是我正在使用的代码的简化版本

Hello all,

I am fairly new to c, coming from a Java background. I am working on a mathematical program and I have a function that needs to return a 2-d array. After some web searching, I have determined that in c, it is better to just pass the array in the function. Since arrays are passed by reference, I expected for the updated array to be passed back with the correct values filled in, however, only the first row of the array is returned (with the rest of the rows filled with zeroes) upon returning from the function. I know that the values are being properly filled in since I verify that before returning from the function (that fills the array). Sorry for the long post, just trying to explain the situation. Below is a simplified version of the code that I''m using

展开 | 选择 | Wrap | 行号

推荐答案

可能有助于查看更多代码,尤其是函数。您可能必须使用指针或双指针传递数组。
It might help to see more of the code, especially the function. You may have to pass the array using pointers or double-pointers.


这里是2个主要函数。其余的代码只是从文件中读取数据,从数据中创建一个数组并将其分解并将其传递给(作为signal [])到getCorrelationIntegral。让我知道这是否足够,或者说信息太多。

here are the 2 principle functions. The rest of the code just reads data from a file, creates an array from the data and breaks it down and passes it (as signal[] ) to getCorrelationIntegral. Let me know if that''s enough, or too much information.

展开 | 选择 | Wrap < span class =codeDivider> | 行号



你好,


我是一个相当新的c,来自Java背景。我正在研究一个数学程序,我有一个需要返回二维数组的函数。经过一些网络搜索后,我确定在c中,最好只传递函数中的数组。由于数组是通过引用传递的,我希望更新的数组能够以填充的正确值传回,但是,从数据库返回后,只返回数组的第一行(其余行用零填充)功能。我知道值正在填写,因为我在从函数返回之前验证了(填充数组)。对不起,很长的帖子,只是想解释一下情况。下面是我正在使用的代码的简化版本

Hello all,

I am fairly new to c, coming from a Java background. I am working on a mathematical program and I have a function that needs to return a 2-d array. After some web searching, I have determined that in c, it is better to just pass the array in the function. Since arrays are passed by reference, I expected for the updated array to be passed back with the correct values filled in, however, only the first row of the array is returned (with the rest of the rows filled with zeroes) upon returning from the function. I know that the values are being properly filled in since I verify that before returning from the function (that fills the array). Sorry for the long post, just trying to explain the situation. Below is a simplified version of the code that I''m using

展开 | 选择 | Wrap | 行号


这篇关于需要帮助返回或通过引用二维数组传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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