i have a problen in creating a linked list

This is a discussion on i have a problen in creating a linked list within the C Programming forums, part of the General Programming Boards category; i have a head variable i initialize a temporary variable "t" wich holds the head and i do a for ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    i have a problen in creating a linked list

    i have a head variable
    i initialize a temporary variable "t" wich holds the head
    and i do a for loop till the "t" variable reaches NULL
    in that case i do malloc and put my new values in the new node

    the problem is that its not working write from the start
    after the for loop ends (creating a second node)
    and i do malloc

    i look at the compiler and it shows me that the next node after head is NULL
    although i just now did malloc
    and even when i put values to "t"

    they next of the head is still NULL
    ??

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    You need to move to the last node in the list, and then assign that node's next pointer to the one you just created. If you iterate through the loop until "t" reaches NULL, then you've gone too far.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks
    that worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 07:16 PM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Creating a global linked list?
    By TwistedJester in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 03:23 AM
  4. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21