#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Linked List Error in C programming


    Dear All,


    i had write a code in C, but when execute, it an error.

    May i know how to combine a correct structure ? kindly advise, thank you

    Output results

    **Enter integers: 23 12 34 56 78 12

    Traversing the list : 23->12->34->56>78->12

    Minimum value : 12

    Reversing the list: 12->78->56->34->12->23**







    #include<stdio.h>
    #include<stdlib.h>


    struct node
    {
    int data;
    struct node *next;
    }*head;



    void insert_data(int value)
    {
    struct node *var,*temp;
    temp=head;
    var=(struct node *)malloc(sizeof(struct node));
    var->data=value;

    if(head==NULL)
    {
    head=var;
    head->next=NULL;
    }
    else
    {
    while(temp->next!=NULL)
    {
    temp=temp->next;
    }
    var->next=NULL;
    temp->next=var;
    }
    }



    void reverse_list()
    {
    struct node *temp,*temp1,*var;
    temp=head;
    var=NULL;
    while(temp!=NULL)
    {
    temp1=var;
    var=temp;
    temp=temp->next;
    var->next=temp1;
    }
    head=var;
    }



    void display()
    {
    struct node *var;
    var=head;
    printf("\nlist of elments are \n");

    while(var!=NULL)

    {
    printf(" %d ->",var->data);
    var=var->next;
    }
    }




    int main()
    {
    int i,value;
    char ch='y';
    head=NULL;


    printf("\nEnter Integers: ");
    scanf("%d",&value);
    insert_data(value);
    display();


    }
    getch();
    }
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    There's an extra right brace `}' at the end of your program. (nor does it choose the value it returns to the operating system)

    $ gcc -Wall c.c
    c.c: In function 'main':
    c.c:75:8: warning: unused variable 'ch' [-Wunused-variable]
    c.c:74:7: warning: unused variable 'i' [-Wunused-variable]
    $ ./a.exe
    8

    Enter Integers:
    list of elments are
    8 ->$


    The program, though incomplete, otherwise works.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo