如何从C中的函数返回2D数组? [英] How to return a 2D array from a function in C?

查看:85
本文介绍了如何从C中的函数返回2D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ruby程序员,最终开发了C语言生成的代码.就像要求一辆Limo拖一辆1960年代的卡车一样.可以.

I am a Ruby programmer who has ended up developing a code generate for C. Its like asking a Limo to tow a 1960s truck. Any way.

这是我认为应该起作用但不起作用的东西.

Here is what I thought should work but doesnt work.

float[][] pixels()
{
  float x[][]= { {1,1},{2,2} };
  return x
}

void drawLine(float x[][2])
{
  //drawing the line
}

//inside main
drawLine(pixels());

我已经把头撞在桌子上,试图使这东西正常工作.请帮忙.

I have banged my head on my desk trying to get this thing work. Please help.

推荐答案

谢谢大家的回答,尤其是对数组指针关系的详细说明.

Thank you all for your answers and more specifically for the detailed explanation of the array-pointer relationship.

我将数组封装在一个结构中

I encapsulated the array in a structure

 struct point_group1 {
        float x[3];
        float y[3];
};

struct point_group1 pixels(){
    struct point_group1 temp;

    temp.x[0] = 0.0;
    temp.x[1] = 1.0;
    temp.x[2] = -1.0;

    temp.y[0] = 0.0;
    temp.y[1] = 1.0;
    temp.y[2] = 1.0;

    return temp;    
}



struct point_group1 points1  = pixels();
axPoly(points1.x, points1.y ,3, 0.0);

这篇关于如何从C中的函数返回2D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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