Results 1 to 4 of 4
  1. #1
    Hey here is the aks arunks's Avatar
    Join Date
    Jan 2006
    Location
    punjab
    Posts
    804

    Default Hey i m getting only one error...Plz help to rectify that

    I m writing a program for various operations on linked list in C... Program is given below.. and i m getting one error and two warnings..
    Plz see by executing it and help me to remove it and run the program successfully...

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    struct node
    {
    int info;
    struct node *next;
    };
    
    void create_list(struct node **head)
    {
    *head = (struct node *) NULL;
    }
    
    struct node *search(struct node *head,int item)
    {
    while(head!=(struct node *) NULL)
    {
    if(head->info==item)
    return head;
    head=head->next;
    }
    return NULL;
    }
    
    void insert_at_beginning(struct node *head,int item)
    {
    struct node *ptr;
    ptr=(struct node *) malloc (sizeof(struct node));
    ptr->info=item;
    if(head==(struct node *)NULL)
    {
    ptr->next=(struct node *)NULL;
    }
    else
    ptr->next=head;
    head=ptr;
    }
    
    void insert_at_end(struct node *head,int item)
    {
    struct node *ptr;
    ptr=(struct node * )malloc(sizeof(struct node));
    ptr->info=item;
    ptr->next=(struct node *)NULL;
    if(head==(struct node *)NULL)
    {
    head=ptr;
    }
    else
    {
    while(head->next!=(struct node *)NULL)
    {
    head=head->next;
    }
    head->next=ptr;
    }
    }
    
    
    void insert_after_element(struct node *head,int item,int after)
    {
    struct node *ptr,*loc;
    loc =(struct node *) search(head,after);
    if(loc== ( struct node * ) NULL )
    {
    printf("no element specified is there");
    return;
    }
    ptr=(struct node *)malloc(sizeof(struct node));
    ptr->info=item;
    ptr->next=loc->next;
    loc->next=ptr;
    }
    
    void traverse_list(struct node *head)
    {
    while(head!= (struct node * ) NULL)
    {
    printf("%d\n",head->info);
    head=head->next;
    }
    }
    
    
    
    void delete_at_beginning(struct node *head)
    {
    struct node *ptr;
    if(head==(struct node *)NULL)
    return;
    else
    {
    ptr=head;
    head= head->next;
    free(ptr);
    }
    }
    
    void delete_at_end(struct node *head)
    {
    struct node *ptr,*loc;
    if(head== (struct node *)NULL)
    return;
    else
    if(head->next==(struct node *)NULL)
    {
    ptr=head;
    head=(struct node *)NULL;
    free(ptr);
    }
    else
    {
    loc=head;
    ptr=head->next;
    while(ptr->next!= (struct node *)NULL)
    {
    loc=ptr;
    ptr=ptr->next;
    }
    loc->next=(struct node *) NULL;
    free(ptr);
    }
    }
    
    
    void delete_after_element(struct node *head,int after)
    {
    struct node *ptr, *loc;
    loc=search(head,after);
    if(loc==(struct node *)NULL)
    return;
    ptr=loc->next;
    loc->next=ptr->next;
    free(ptr);
    }
    
    void delete_list(struct node *head)
    {
    struct node *ptr;
    while(head != (struct node *)NULL)
    {
    ptr=head;
    head=head->next;
    free(ptr);
    }
    }
    
    
    main()
    {
    struct node *head;
    int choice,item,after;
    clrscr();
    
    printf("Linked List Program\n\n\n Press any key to start!!!!!!");
    
    while(1)
    {
    clrscr();
    printf("Linked List Program\n\n\n");
    printf("1. Create a new linked list\n\n");
    printf("2. Insert an element at the beginning\n\n");
    printf("3. Insert an element after an element\n\n");
    printf("4. Insert an element at end\n\n");
    printf("5. Traverse all the elements of linked list\n\n");
    printf("6. Search an element in linked list\n\n");
    printf("7. Delete an element at the beginning\n\n");
    printf("8. Delete an element after an element\n\n");
    printf("9. Delete an element at end\n\n");
    printf("10.Exit\n\n");
    printf("\n\nEnter the choice:(1-10)");
    scanf("%d",&choice);
    if(choice<1 || choice>9)
    {
    clrscr();
    printf("enter correct choice\n");
    }
    else
    if(choice==1)
    {
    create_list(&head);
    printf("empty List created\n");
    }
    else
    if(choice==2)
    {
    printf("Enter the no. to store\n");
    scanf("%d",&item);
    insert_at_beginning(head,item);
    }
    else
    if(choice==3)
    {
    printf("Enter the no. to store\n");
    scanf("%d",&item);
    printf("Enter no. after which %d is to be stored\n",item);
    scanf("%d",&after);
    insert_after_element(head,item,after);
    }
    else
    if(choice==4)
    {
    printf("Enter the no. to store\n");
    scanf("%d",&item);
    insert_at_end(head,item);
    }
    else
    if(choice==5)
    {
    if(head==(struct node *)NULL)
    printf("\n List is empty......");
    else
    traverse_list(head);
    printf("\nPress any ley to continue.......");
    getch();
    }
    else
    if(choice==7)
    {
    delete_at_beginning(head);
    }
    else
    if(choice==8)
    {
    printf("Enter the no. after which item is to be deleted\n");
    scanf("%d",&after);
    delete_after_element(head,after);
    }
    else
    if(choice==9)
    {
    delete_at_end(head);
    }
    else
    if(choice==10)
    {
    delete_list(head);
    exit(1);
    }
    }
    getch();
    }
    Last edited by arunks; 27-08-2007 at 09:00 AM.
    yours truly
    arun
    The aks!!

    have a nice day

  2. #2
    Dreamweaver Gigacore's Avatar
    Join Date
    Aug 2006
    Location
    Bangalore
    Posts
    3,885

    Default Re: Hey i m getting only one error...Plz help to rectify that

    please tell the error it states
    Today's noobs are tomorrow's geeks. Don't make fun of them.. encourage them. - Gigacore

    Follow me on twitter.com/gigacore

  3. #3
    Hey here is the aks arunks's Avatar
    Join Date
    Jan 2006
    Location
    punjab
    Posts
    804

    Default Re: Hey i m getting only one error...Plz help to rectify that

    I have removed the error myself... now program is executing without any error... but there is logical error i mean to say the output is not as expected.. plz check!!!
    yours truly
    arun
    The aks!!

    have a nice day

  4. #4
    Captain Jack Sparrow jacksparrow18's Avatar
    Join Date
    Jan 2007
    Location
    Rajkot,Gujarat
    Posts
    17

    Thumbs down Re: Hey i m getting only one error...Plz help to rectify that

    Quote Originally Posted by arunks
    I have removed the error myself... now program is executing without any error... but there is logical error i mean to say the output is not as expected.. plz check!!!
    write statement of ur prog!!!!!!!!!!!!!!
    Gaurav Chauhan

    The only thing i like about the stones is that they come in my life,and when i cross them automatically they become milestones of my life!!!

Similar Threads

  1. how to rectify this......???
    By pr.itdude in forum QnA (read only)
    Replies: 5
    Last Post: 10-05-2009, 06:53 PM
  2. Help!!!!!! How to rectify this My BB SQL error......
    By me_ankitroy in forum QnA (read only)
    Replies: 1
    Last Post: 13-08-2008, 04:11 PM
  3. how to rectify this....................?
    By saurabh kakkar in forum Open Source
    Replies: 4
    Last Post: 27-06-2007, 11:47 PM
  4. fedora core 6 error..plz rectify
    By arunks in forum Open Source
    Replies: 3
    Last Post: 28-03-2007, 09:26 PM
  5. Wats the best way to rectify winrar error ?
    By vinyas in forum Software Q&A
    Replies: 5
    Last Post: 03-10-2006, 02:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Close