Thread: strange linked list problem

  1. #1

    strange linked list problem

    Normaly I would post this in the C++ board, but I think the problem is windows related.

    I have class witch can add nodes and brows through a linked list.
    the function that adds the node looks like this:
    Code:
    bool CMP3LIST::AddToList(int length,char title[MAX_PATH],char filepath[MAX_PATH])
    {	
    	if (firsttime)
    	{
    		nieuw=(MP3STRUCTLIST *)malloc(sizeof(MP3STRUCTLIST));		
    		eerst=deze=nieuw;
    		firsttime = false;
    	}
    	else
    	{						
    		deze->nextrecord=(MP3STRUCTLIST *)malloc(sizeof(MP3STRUCTLIST));  
    		deze=deze->nextrecord;			
    		deze->nextrecord=nieuw;	
    	}
    	total_records++;
    	deze->number=total_records;
    	current_record++;
    	deze->length=length;
    	strcpy(deze->name,title);
    	strcpy(deze->path,filepath);
    
    	return true;
    }
    some words are dutch, I'll translate to clearefy (sp?)
    nieuw=new
    deze=this
    eerst=first

    so when I want to add a nod, I call the function like this:
    playlist.AddToList(000,lpofn.lpstrFile,lpofn.lpstr File);
    lpofn is of the type OPENFILENAME
    and lpofn.lpstrFile gets filled in by the GetOpenFileName function from the WIN32 API

    but after the malloc, the value of lpofn.lpstrFile changes. I don't see how this is possible? does windows override a piece of memory that holds the OPENFILENAME data? and strangly, there is just one letter that changes in the filename
    example: c:\My Documents\... changes to c:\My DoTuments\...

    How is this possible????
    is there some underlying memory bug somewhere that I'm not aware of.

    I corrected the problem by adding a strcpy before the addtolist function, like this:
    Code:
    strcpy(buffer,lpofn.lpstrFile);
    playlist.AddToList(000,buffer,buffer);
    it works, but it doesn't give me an explination why this happens.
    and the lpofn.lpstrFile still changes and it isn't even part of the class it is a global variable.

    anyone has an idea about this, why this happens?

    thx

    --Maes

    BTW, if my function to add nodes contains bugs, or there are better ways to do it, let my know
    Last edited by maes; 09-06-2003 at 09:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  3. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM
  4. Linked List problem
    By spec85 in forum C Programming
    Replies: 1
    Last Post: 06-14-2002, 03:58 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM