Skip navigation.
 
mlRe: linked list problem
FROM : stephen joseph butler
DATE : Mon Mar 31 23:39:22 2008

On Mon, Mar 31, 2008 at 4:31 PM, Nick Rogers <<email_removed>> wrote:

> Hi,
> I have the following singly linked list:
>
> typedef struct Dir
> {
>        // some space to hold data here
>        void *next;    // have to take void * here cause Dir* leads to
> compile
> error
> }DIR;



It won't compile because at this point Dir isn't typedefed, so C requires
"struct Dir". So...

typedef struct Dir
{
      // some space to hold data here
      struct Dir *next;
}DIR;


> In my code:
>
> DIR *temp = parentDir;  //parentDir is allocated initially but its
> next is not allocated at this point
> while (temp)
> {
>        temp = (DIR*)temp->next;        //here next is null so, temp now is
> null
> }
> temp = newDir;          //here newDir is already allocated, but temp
> doesn't
> get allocated, in a way parentDir->next remains null.
>
>
> While this type of code works fine on VS2005, it doesn't wprk here in
> cocoa.
> How else can I reach the end of the list and add a new node?



There is no way the code you show works for any C compiler, let alone
VS2005. You never do the linking part of the linked list.

Besides, none of this is really Cocoa so it doesn't belong on this list.

Related mailsAuthorDate
mllinked list problem Nick Rogers Mar 31, 23:31
mlRe: linked list problem stephen joseph but… Mar 31, 23:39
mlRe: linked list problem Andrew Farmer Apr 1, 00:19
mlRe: linked list problem Jean-Daniel Dupas Apr 1, 00:33