From: "Anthony Nguyen" <nguyenanthony@wanadoo.fr>
To: linux-c-programming@vger.kernel.org
Subject: RE: dynamic allocation of array of structures
Date: Sat, 22 Mar 2003 21:27:19 +0100 [thread overview]
Message-ID: <20030322202720.267284000B9@mwinf0501.wanadoo.fr> (raw)
In-Reply-To: <Pine.LNX.4.21.0303222034440.5699-100000@hestia>
typedef struct Apeople {
char *name;
int telnr;
} Tpeople;
...
Tpeople *toto;
toto = (Tpeople *)(malloc (sizeof Tpeople) * <the number of elements you
want to allocate>);
But I think that you were searching a "proper way" to implement it, isn't it
:?
A.N.
-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org] On Behalf Of J.
Sent: Saturday, March 22, 2003 8:48 PM
To: linux-c-programming@vger.kernel.org
Hello,
struct {
char *name;
int telnr;
} people[100];
Instead of statically allocating an array of 100 of these structures like
I have done, I want to dynamically allocate the array at run-time and
resize the number of structures some where at any time in the main
program.
I know how to resize char arrays and int arrays but I never (re)sized an
array of structres which can be accessed with something as:
``people[4].name''.
In Google nothing really usefull turns up.
Can this be done without having to resort to other implementations like
linked lists etc.. ? If so how ?
Thank you in advance.
J.
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2003-03-22 20:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-28 3:26 ODBC Under Linux chuckw
2003-02-28 21:31 ` Glynn Clements
2003-03-19 13:22 ` How to open a file and to disable other processes from removing it Alexi Jordanov
2003-03-19 15:45 ` Glynn Clements
2003-03-22 19:47 ` dynamic allocation of array of structures J.
2003-03-22 20:27 ` Anthony Nguyen [this message]
2003-03-22 20:48 ` J.
2003-03-22 21:00 ` Elias Athanasopoulos
2003-03-22 21:28 ` Glynn Clements
2003-03-22 21:44 ` dynamic allocation of array of structures, Thnkx J.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030322202720.267284000B9@mwinf0501.wanadoo.fr \
--to=nguyenanthony@wanadoo.fr \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).