creating link list and reading it to print output

This is a discussion on creating link list and reading it to print output within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> struct node { struct node *next; int nodevalue; }; struct node *start,*tail; struct node *createlist(int ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    10

    creating link list and reading it to print output

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
    #include<stdlib.h>
    struct node 
    {
           struct node *next;
           int nodevalue;
    };
    struct node *start,*tail;
    struct node *createlist(int x);
     main()
    {       int i;
           struct node * temp1;
         start=(struct node *)malloc(sizeof(struct node));
         tail=start;
               createlist(48);
               createlist(65);
               createlist(98);
                temp1=start->next;
               for(i=0;i<1;i++)
               temp1=temp1->next;
               printf("value is %d ",temp1->nodevalue);
              
     getch();
    }
    struct node *createlist(int x)
    {
           struct node *temp;
               
                if(temp=(struct node *)malloc(sizeof(struct node)))
                {
                 temp->nodevalue=x;
                 temp->next=NULL;
                 tail->next=temp;
                 temp=tail;
                 return tail;
                 }
                  if(tail==start && tail->nodevalue==NULL)
                {
                   printf("list empty");
                   } 
                 else
                 printf("memory shortage");
                return NULL;
    }

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    when i run this program i find segmentation fault how can i remove this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading data from a file - link list
    By peter_hii in forum C++ Programming
    Replies: 7
    Last Post: 10-25-2006, 10:11 AM
  2. Left justification using linked list of link list
    By hykyit in forum C Programming
    Replies: 7
    Last Post: 08-29-2005, 11:04 PM
  3. Weird Output...(Link list)
    By davidvoyage200 in forum C++ Programming
    Replies: 1
    Last Post: 05-11-2003, 10:07 PM
  4. Link list problem->can't print the output...
    By frankiepoon in forum C Programming
    Replies: 1
    Last Post: 11-09-2002, 12:01 AM
  5. Link List output
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-30-2001, 09:57 AM

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