Re: [Dev-C++] System crash happen when I run a very simple linear list' program.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jorge A. <jor...@ep...> - 2004-06-02 01:16:46
|
You have to allocate memory for the structure before allocate the array
inside.
Bruce jjs escribi=A8=AE:
> I have writed a simple program just only construct two empty linear
> list.The process of compile is no problem.But after run it,the system
> crash occur.If I remove the sentence (2),the problem will not come.Can
> anyone tell me how to do If I want to use the function InitList()
> separate to construct two empty list?
> Thanks,
> Bruce.J
> My program list below:
> /* A simple program that want to construct two empty linear list */
> #define LIST_INIT_SIZE 10
> typedef int ARRAY;
> typedef struct {
> ARRAY *elem; /* a pointer of one dimension array */
> int length; /*the linear list current length */
> int listsize; /* the linear list's space that has distributed */
> }LineList;
>
> /* construct a empty linear list */
> ARRAY *InitList(LineList *list)
> {
> list->elem =3D (ARRAY *) malloc(LIST_INIT_SIZE * sizeof(ARRAY));
> list->length =3D 0;
> list->listsize =3D LIST_INIT_SIZE;
> return list->elem;
> }
> main()
> {
> LineList *list, *list1;
>
> /* want to create two empty linear list */
> list->elem =3D InitList(list); /* sentence (1) */
> list1->elem =3D InitList(list1); /* sentence (2) */
> system("PAUSE");
> }
>
>
> -----------------------------------------------------------------------=
-
> *Do You Yahoo!?*
> =CF=D3=D3=CA=CF=E4=CC=AB=D0=A1=A3=BF=D1=C5=BB=A2=B5=E7=D3=CA=D7=D4=D6=FA=
=C0=A9=C8=DD=A3=A1
> <http://cn.rd.yahoo.com/mail_cn/tag/10m/*http://cn.mail.yahoo.com/event=
/10m.html>
|