本文介绍了malloc for multidimensional array !!请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检索动态二维数组中的数据时遇到了大问题。


i我正在计算并将数据保存到动态二维数组中。

但是当我检索它们时,它没有给出正确的值。


您可以在C编译器中运行以下代码并查看差异


follwoing是我的代码,请看一下,请回复


电子邮件:rjh在上述域名, - www。

foo.c:6: warning: return-type defaults to `int''
foo.c:6: warning: function declaration isn''t a prototype
foo.c: In function `main'':
foo.c:13: warning: implicit declaration of function `malloc''
foo.c:13: warning: cast does not match function type
foo.c:38: warning: implicit declaration of function `free''
foo.c:39: warning: control reaches end of non-void function

Fix these problems first, then post again if you''re still having trouble.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.




< snip>

<snip>



用stdlib.h替换上面的标题

Replace above header with stdlib.h



将以上替换为int main(无效)

Replace above with int main(void)



请:a = malloc(lx * 2);

检查是否成功。

Do: a = malloc(lx * 2);
Check for success.



完全错误。做:

a [i] [j] = i + j * 0.3;

Completely wrong. Do:
a[i][j] = i + j * 0.3;



再次:

printf(" a [%d] [%d] =%f \ n,i,j ,a [i] [j]);

Again:
printf("a[%d][%d] = %f\n", i, j, a[i][j]);



重复代码有什么意义?

What''s the point of repeating the code?




< ;剪断>

<snip>



用stdlib.h替换上面的标题


Replace above header with stdlib.h



将以上替换为int main(无效)


Replace above with int main(void)



请:a = malloc(lx * 2);

检查是否成功。


Do: a = malloc(lx * 2);
Check for success.



哎呀。这应该是:

a = malloc(lx * sizeof * a);


< snip>

Whoops. This should be:
a = malloc(lx * sizeof *a);

<snip>


这篇关于malloc for multidimensional array !!请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 23:03