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

问题描述

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


这就是我正在做的事情:

创建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;
}
}
}

推荐答案




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


-

: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





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

07-07 19:51