指向结构指针的指针。 [英] Pointer to pointers of structs.

查看:117
本文介绍了指向结构指针的指针。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我希望我的主题正确..


这就是我正在做的事情:

创建P(变量)多边形每个都有可变数量的顶点,我的mallocs中的东西是错误的...因为我得到了奇怪的结果。


帮助?


#include< stdio.h>

#include< stdlib.h>


typedef struct point

{

双x,y;

}点;


typedef struct polygon

$

int n;

point * v;

} polygon;


typedef struct line

{

point p1,p2;

double A,B;

} line;


#define P 2


int main()

{

int i = 0,j = 0;


多边形*障碍= malloc(sizeof *障碍* P);


for(i = 0; i < P; i ++)

{

障碍[i] .n = i + P * 2;

障碍[i] .v = malloc(sizeof障碍[i] .v *障碍[i] .n);


for(j = 0; j<障碍[I] .N; i ++)

{

障碍[i] .v [j] .x =障碍[i] .n;

障碍[i] .v [j] .y =障碍[i] .n + 5;

}

}

}

Hi I hope I got the topic right..

that''s what I''m doing:
create P(variable) polygons each having a variable numbers of vertices,
something in my mallocs is wrong... since I get weird results.

help?

#include <stdio.h>
#include <stdlib.h>

typedef struct point
{
double x, y;
} point;

typedef struct polygon
{
int n;
point *v;
} polygon;

typedef struct line
{
point p1, p2;
double A, B;
} line;

#define P 2

int main()
{
int i = 0, j = 0;

polygon *obstacles = malloc(sizeof *obstacles * P);

for(i = 0; i < P; i++)
{
obstacles[i].n = i + P * 2;
obstacles[i].v = malloc(sizeof obstacles[i].v * obstacles[i].n);

for(j = 0; j < obstacles[i].n; i++)
{
obstacles[i].v[j].x = obstacles[i].n;
obstacles[i].v[j].y = obstacles[i].n + 5;
}
}
}

推荐答案

jo ******** @ gmail.com 写道:
jo********@gmail.com wrote:
创建P(变量)多边形,每个多边形都有可变数量的顶点,我的mallocs中的某些内容是错误的...我得到了奇怪的结果。
create P(variable) polygons each having a variable numbers of vertices,
something in my mallocs is wrong... since I get weird results.




请更具体一点:奇怪的结果是什么意思?


-

:wq

^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C



Please be more specific: what do you mean by ''weird results'' ?

--
:wq
^X^Cy^K^X^C^C^C^C


>请更具体一点:奇怪的结果是什么意思?

为了更清楚,该程序还没有完成运行。我非常好

肯定我已经在mem-allocation中搞了一个混乱......


谢谢。

>Please be more specific: what do you mean by ''weird results'' ?
To make it clearer, the program doesn''t finish runing. I''m quite
certain I''ve made a copmlete mess out of the mem-allocation...

Thanks.


jo ******** @ gmail.com 写道:
嗨我希望我的主题正确..

这就是我正在做的事情:
创建P(变量) )每个都有可变数量的顶点的多边形,在我的mallocs中的某些东西是错误的...因为我得到了奇怪的结果。

帮助?
[...]
int main()
{i / 0,j = 0;

多边形*障碍= malloc(sizeof *障碍* P);

for(i = 0; i< P; i ++)
{
障碍[i] .n = i + P * 2;
障碍[i] .v = malloc(sizeof障碍[i] .v *障碍[i] .n);

(j = 0; j<障碍[i] .n; i ++)
^^

可能你的意思是上面的循环中的j ++。

{
障碍[i]。 v [j] .x =障碍[i] .n;
障碍[i] .v [j] .y =障碍[i] .n + 5;
}
}
}
Hi I hope I got the topic right..

that''s what I''m doing:
create P(variable) polygons each having a variable numbers of vertices,
something in my mallocs is wrong... since I get weird results.

help? [...]

int main()
{
int i = 0, j = 0;

polygon *obstacles = malloc(sizeof *obstacles * P);

for(i = 0; i < P; i++)
{
obstacles[i].n = i + P * 2;
obstacles[i].v = malloc(sizeof obstacles[i].v * obstacles[i].n);

for(j = 0; j < obstacles[i].n; i++) ^^
Likely you mean j++ in the above for loop.
{
obstacles[i].v[j].x = obstacles[i].n;
obstacles[i].v[j].y = obstacles[i].n + 5;
}
}
}



这篇关于指向结构指针的指针。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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