| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
| content-class: | urn:content-classes:message |
| MIME-Version: | 1.0 |
| X-MimeOLE: | Produced By Microsoft Exchange V6.0.6249.0 |
| Subject: | RE: pointers to structs |
| Date: | Wed, 14 Jul 2004 18:20:16 -0400 |
| Message-ID: | <ACAAE6BD7520AB4CB2744D1D1BAD3A2BA1446E@jupiter.insideai.com> |
| X-MS-Has-Attach: | |
| X-MS-TNEF-Correlator: | |
| Thread-Topic: | pointers to structs |
| Thread-Index: | AcRp8ES9SRTo4fogTNuqH65Zq4vZeQAACP0A |
| From: | "John Bond" <Jbond AT ai-logix DOT com> |
| To: | <djgpp AT delorie DOT com> |
| X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id i6EMWvXU014597 |
| Reply-To: | djgpp AT delorie DOT com |
You need to allocate the list memory first like so:
list = (struct data_list *) malloc(sizeof(struct data_list));
Then you should check that list != NULL, before using it! -John Bond
YOU WROTE:
-----Original Message-----
From: John Hanley [mailto:jdhanley AT telusplanet DOT net]
Sent: Wednesday, July 14, 2004 6:03 PM
To: djgpp AT delorie DOT com
Subject: pointers to structs
I am creating a linked list. I have 2 structs:
struct data_record
{
struct data_record * next;
};
struct data_list
{
struct data_record * head;
struct data_record * tail;
};
int main()
{
struct data_list * list;
list->head = NULL;
list->tail = NULL;
}
When I compile then run this, I get: "Exiting due to Signal SIGSEGV. Page
Fault at ..."
Can I not assign NULL to these pointers? If I take the 2 assignments out,
it runs ok.
Any suggestions as to why I can't initialize my head and tail to NULL?
Thanks!
John
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |