Thread: Problem with nodes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Question Problem with nodes

    Good day guys!
    I am an IT student currently learning linked list. I have a problem with my code here. After I call addFront() my list doesn't change when I display it. How do I somewhat change/fill my list without changing the function type? I know it works on pointers still messed up with linked list.




    list.h

    Code:
    typedef struct node *nodeptr; 
    
    struct node{
    int item; nodeptr next;
    }; typedef nodeptr List; void addFront(List head, int item); void display(List list);


    list.c
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include"list.h"
    
    void addFront(List head, int item){
    List temp; temp = (List)malloc(sizeof(List)); temp->item = item; temp->next=head; head=temp;
    } void display(List list){
    List ptr=list; while(ptr!=NULL){
    printf("%d ", ptr->item); ptr=ptr->next;
    }
    }
    main.c
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include"list.h"
    
    int main(){
    List head=NULL; addFront(head, 5); display(head);
    }
    Last edited by Clyde Sanchez; 02-13-2013 at 05:08 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem transferring nodes between linked lists
    By NotAProgrammer in forum C Programming
    Replies: 1
    Last Post: 04-07-2012, 03:38 PM
  2. Problem with Nodes, Ancestry!
    By Ervilha in forum C Programming
    Replies: 1
    Last Post: 04-14-2010, 10:05 AM
  3. Programmatically creating nodes in a treeview problem
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 10-12-2006, 02:41 PM
  4. Logic problem adding nodes to linked list
    By SeanMSimonsen in forum C++ Programming
    Replies: 0
    Last Post: 04-02-2003, 07:04 PM
  5. Help w/nodes
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2002, 08:09 PM