www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/19/08:01:08

From: Edward Hill <ha AT nochance DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A Structured Problem ?
Date: Mon, 19 Jul 1999 12:21:29 +0100
Organization: GEC-Marconi
Lines: 37
Message-ID: <37930A39.4C2C00BE@nochance.com>
References: <7mv0te$gq2$1 AT news6 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: pc02372.gmsws.gecm.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.51 [en] (Win95; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Paul J G wrote:
:
: Hi Guys, I really need some help big time on this one, can anyone help
put
: me out of my misery ?.
: Right, I have a structure in my program:
: 
: struct { float xpoint[9],float ypoint[9] } shape[10];
[snip]
: Not knowing what the varibles xpoint, ypoint, will be at compilation
time
: they must be dynamically
: allocated, as the file length for each shape could vary.
: The idea being that I can load my 3d objects into the shape varibles.

I seems you know wat you must do, dynamically allocate.

struct {
    float *xpoint;
    float *ypoint;
    }shape[10];

now just before you assign them,
don't forget to include stdlib.h,

shape[1].xpoint = malloc(sizeof(float) * 9);
shape[1].ypoint = malloc(sizeof(float) * 9);
shape[2].xpoint = malloc(sizeof(float) * 25);
shape[2].ypoint = malloc(sizeof(float) * 25);

you should check the return of malloc in case it's null for each.

you can then shape[1].xpoint[0] = 1.345;
             shape[1].xpoint[1] = 1,2353;
             ...

Ed

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019