Ok, I'm pretty sure this is a pointer another problem
I'm coding a demo using SDL. For the text each letter is going to be an object:
struct letter
{
float x, y;
char ch;
struct letter *next;
}; typedef struct letter letter;
letter *NewLetter(letter **head)
{
letter *newnode;
if(!(newnode = malloc(sizeof(*newnode))))
return NULL;
newnode->next=*head;
*head = newnode;
return newnode;
}When the program starts I create a set of letters from main:
letter *letterhead=NULL;
InitLetters(30, 100, 4, 3, "SOMETHING IS GOING ON", letterhead);Heres the function where they are created:
void InitLetters(int x, int y, int space, int randy, char* txt, letter *lh)
{
int pos=0;
while(*txt)
{
lh=NewLetter(&lh);
lh->x=x+pos+space+Rand(-randy, randy);
lh->y=y+Rand(-randy, randy)*3;
lh->ch=*txt;
pos+=FONT_WIDTH;
txt++;
}
} In my main loop I then draw each letter:
void DrawLetters(letter *lh)
{
src.w=FONT_WIDTH;
src.h=FONT_HEIGHT;
while(lh != NULL)
{
exit(1);
if(lh->ch > ' ' && lh->ch < '[')
{
dest.x=lh->x;
dest.y=lh->y;
src.x=((lh->ch-' ')%FONTSET_WIDTH)*FONT_WIDTH;
src.y=((lh->ch-' ')/FONTSET_WIDTH)*FONT_HEIGHT;
SDL_BlitSurface(font, &src, screen, &dest);
}
lh=lh->next;
}
}Now I added 'exit(1)' to the loop in this function so the prog should quit at the first letter, but it dosent. This should mean that none of the letters were actually created in the InitLetters function.
Someone know whats wrong here?