Advertisement

linked list and NULLS

Started by August 21, 2000 03:33 PM
6 comments, last by Bruno 24 years, 4 months ago
Hi If i have this structure, should''t this stop when there is a NULL struct???? struct POLYGON { VERTEX VertexList[10]; VERTEX Normal; WORD NumberOfVertices; WORD NumberOfIndices; WORD Indices[30]; POLYGON * Next; }; POLYGON * yadda; while{yadda!=NULL) { printf("%i\n",yadda->VertexList[0]); } thanks Bruno The damn while cicle doens''t stop in the null, he goes and goes.. what''s wrong with this piece of code?
Look at your while loop for a few minutes. Look hard

Don''t see it? You''re missing yadda = yadda->Next.
Advertisement
First, DON''T FORGET TO INITIALIZE YOUR ELEMENTS. The success of what you''re trying to do is dependent on two things: that from the head of the list back, POLYGON->Next points to the successive POLYGON, that the tail of the list, the final POLYGON, has its POLYGON->Next = NULL.
while( yadda != NULL ){    printf( "%i\n", yadda->VertexList[0] );    yadda = yadda->Next; // forget something?}

That should do it, provided your linked list is set up properly.
Ummm???? _Look_ _at_ _it_ - your loop code doesn''t move the pointer onward...
yadda=yadda->Next 


Jans.


-----------------
Janucybermetaltvgothmogbunny
I''m sorry, i forgot to put the line
yadda=yadda->next.
But tha it''s not the problem, i have it on my code, i just forgot to put it here.
And, when i finish the filling of the structure, i also point the yadda->next to Null..
The problem, is that, in the Debug, i can see the variable yadda->VertexList[0] and others equal to -1.4444e+21 or something.., the values the the variables have when they are empty, just after the creation, i can see she is NULL, and the debuger goes on, and then, later when i assing or make calculations with this values, i have a crash.
I have tried to substitute in the While condition yadda!=NULL by yadda->next!=NULL but the outcome is the same
I really don''t get it

Bruno
Post your code. There''s always a reason why something doesn''t work.
Advertisement
Hi
my source is this:



This is where i fill my structure:

poly_ini = (struct polyg *)malloc(sizeof(struct polyg));
poly_next=poly_ini;
apont=ini;
num=0;
do{

poly_next->VertexList[0] = apont->x;
poly_next->VertexList[1] = apont->y;
poly_next->VertexList[2] = apont->z;
apont=apont->prox;

poly_next->VertexList[3] = apont->x;
poly_next->VertexList[4] = apont->y;
poly_next->VertexList[5] = apont->z;
apont=apont->prox;

poly_next->VertexList[6] = apont->x;
poly_next->VertexList[7] = apont->y;
poly_next->VertexList[8] = apont->z;
apont=apont->prox;

poly_next->VertexList[9] = apont->x;
poly_next->VertexList[10] = apont->y;
poly_next->VertexList[11] = apont->z;
apont=apont->prox;
poly_next->Next =(struct polyg *)malloc(sizeof(struct polyg));
poly_next=poly_next->Next;
num+=4;
}while(num!=number_polys);
poly_next=NULL;

ok, now the function where it crashes:




POLYGON SelectBestSplitter(POLYGON PolyList)
{
POLYGON Splitter=PolyList;
POLYGON CurrentPoly=NULL;
unsigned long BestScore=100000;
POLYGON SelectedPoly=NULL;


while (Splitter!=NULL)
{
num=num+4;
CurrentPoly=PolyList;
unsigned long score,splits,backfaces,frontfaces;
score=splits=backfaces=frontfaces=0;
while (CurrentPoly !=NULL) -----> THIS IS WHERE THE PROBLEM IS!!

{


if (CurrentPoly!=Splitter) -----> THIS IS WHERE THE PROBLEM IS!!
{

int result=ClassifyPoly(Splitter,CurrentPoly,num);
switch ( result)
{
case CP_ONPLANE:
break;
case CP_FRONT:
frontfaces++;
break;
case CP_BACK:
backfaces++;
break;
case CP_SPANNING:
splits++;
break;
default:
break;
}
}

CurrentPoly=CurrentPoly->Next;
}



Any ideias???
thanks

Bruno
hello

You shouldnt forget the pointers..


POLYGON *SelectBestSplitter(POLYGON *PolyList)
{
POLYGON *Splitter=*PolyList;
POLYGON *CurrentPoly=NULL;
unsigned long BestScore=100000;
POLYGON *SelectedPoly=NULL;


while (Splitter)
{
num=num+4;
CurrentPoly=PolyList;
unsigned long score,splits,backfaces,frontfaces;
score=splits=backfaces=frontfaces=0;
while (CurrentPoly)
{


if (CurrentPoly!=Splitter) // I think you have to define
// an operator for this

{
:
:
:



I hope this helps

This topic is closed to new replies.

Advertisement