i am new to programming............i just want to create a linked list program plz check for error for me

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void insertAtEnd(int no);
void insertAtBegin(int no);
void insertAtPos(int no,int pos);
template <span= id="IL_AD" class="IL_AD">Display</span>();
<span id="IL_AD5" class="IL_AD">struct</span> LinkedList
{
         int num;
         struct LinkedList *next;
};
typedef  struct LinkedList <span id="IL_AD11" class="IL_AD">NODE</span>;
NODE *node,*<span id="IL_AD7" class="IL_AD">start</span>,*temp;

int main()
{

    start=<span id="IL_AD12" class="IL_AD">NULL</span>;
    int opt,no,pos;
    char option;
    do
    {
                <span id="IL_AD6" class="IL_AD">printf</span>("\n Main menu");
                printf("\n 1. <span id="IL_AD4" class="IL_AD">insert</span> at Begining");
                printf("\n 2. insert <span id="IL_AD1" class="IL_AD">at End</span>");
                printf("\n 3. insert at <span id="IL_AD8" class="IL_AD">Specific</span> <span id="IL_AD2" class="IL_AD">position</span>");
                printf("\n 4. Display the linked list");
                printf("\n 0. Exit");
                printf("\n Enter yout choice::");
                scanf("%d",&opt);
                switch(opt)
                {
                           case 1:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     insertAtBegin(no);
                                     break;
                           case 2:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     insertAtEnd(no);
                                     break;
                           case 3:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     printf("Enter position::");
                                     scanf("%d",&pos);
                                     insertAtPos(no,pos);
                                     break;
                           case 4:   Display();
                                     break;
                           case 5:   exit(0);
                           default:  printf("invalid option");
                                     break;
                };
                printf("\nwant to continue,(PRESS y for YES:::)");
                scanf("%s",&option);
                }while(option=='y');
                getch();
                return 0;
}

void insertAtBegin(int no)
{
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;
     if(start!=NULL)
     {
                 node->next=start;
                 start=node;
     }
     else
     {
        start=temp=node;
        node->next=NULL;
     }
}

void insertAtEnd(int no)
{
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;
     node->next=NULL;
     if(start!=NULL)
     {
                 temp->next=node;
                 temp=node;
     }
     else
     {
        start=temp=node;
     }

}

void insertAtPos(int no, int pos)
{
     int i;
     if(pos==1)
     {
        insertAtBegin(no);
        return;
     }
     temp=start;
     printf("%d",temp->num);
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;

     for(i=1;i<pos-1;i++)
     temp=temp->next;
     node->next=temp->next;
     temp->next=node;
}

void Display()

                temp=start;
                printf("\ndisplay the linked list\n");
                while(temp->next!=NULL)
                {
                           printf("\n%d",temp->num);
                           temp=temp->next;
                }
                printf("\n%d",temp->num);
}

Recommended Answers

All 13 Replies

The first error is that your code is littered with HTML and won't compile.

so what i should to for that.............

plz correct this all code for me..............plz plz plz

Member Avatar for Mouche

As Narue pointed out, you have HTML in your code which is incorrect. Remove all the span tags (<span= id="IL_AD" class="IL_AD"> and </span>).

Then, compile the code and read the error messages (assuming there are some). If you can't get past an error, reply to the thread showing what you've attempted and what errors you're getting.

i have removed al span etc but know it gives error start temp and node undeclered.....help plz here is the program

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void insertAtEnd(int no);
void insertAtBegin(int no);
void insertAtPos(int no,int pos);
void Display();
struct LinkedList
{
         int num;
         struct LinkedList *next;
};
typedef  struct LinkedList;
NODE *node,*start,*temp;

int main()
{
    int opt,no,pos;
    char option;
    do
    {
                printf("\n Main menu");
                printf("\n 1. insert at Begining");
                printf("\n 2. insert at End");
                printf("\n 3. insert at Specific");
                printf("\n 4. Display the linked list");
                printf("\n 0. Exit");
                printf("\n Enter yout choice::");
                scanf("%d",&opt);
                switch(opt)
                {
                           case 1:   printf("Enter number to b");
                                     scanf("%d",&no);
                                     insertAtBegin(no);
                                     break;
                           case 2:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     insertAtEnd(no);
                                     break;
                           case 3:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     printf("Enter position::");
                                     scanf("%d",&pos);
                                     insertAtPos(no,pos);
                                     break;
                           case 4:   Display();
                                     break;
                           case 5:   exit(0);
                           default:  printf("invalid option");
                                     break;
                };
                printf("\nwant to continue,(PRESS y for YES:::)");
                scanf("%s",&option);
                }while(option=='y');
                getch();
                }

void insertAtBegin(int no)
{
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;
     if(start!=NULL)
     {
                 node->next=start;
                 start=node;
     }
     else
     {
        start=temp=node;
        node->next=NULL;
     }
}

void insertAtEnd(int no)
{
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;
     node->next=NULL;
     if(start!=NULL)
     {
                 temp->next=node;
                 temp=node;
     }
     else
     {
        start=temp=node;
     }

}

void insertAtPos(int no, int pos)
{
     int i;
     if(pos==1)
     {
        insertAtBegin(no);
        return;
     }
     temp=start;
     printf("%d",temp->num);
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;

     for(i=1;i<pos-1;i++)
     temp=temp->next;
     node->next=temp->next;
     temp->next=node;
}

void Display()
{
                temp=start;
                printf("\ndisplay the linked list\n");
                while(temp->next!=NULL)
                {
                           printf("\n%d",temp->num);
                           temp=temp->next;
                }
                printf("\n%d",temp->num);
}

its wrong..

struct LinkedList
{
int num;
struct LinkedList *next;
};
typedef struct LinkedList;
NODE *node,*start,*temp;

you are using

typedef struct LinkedList;

change this line with

typedef struct LinkedList NODE;

brother the program still shows error plz help....i just want to learn something new........plz check my whole program correct it than post plz plz plz.....i would be thank ful to uuuu

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void insertAtEnd(int no);
void insertAtBegin(int no);
void insertAtPos(int no,int pos);
void Display();
struct LinkedList
{
         int num;
         struct LinkedList *Next;
};
typedef struct linkedlist NODE;
NODE *node,*start,*temp;
int main()
{
    int opt,no,pos;
    char option;
    do
    {
                printf("\n Main menu");
                printf("\n 1. insert at Begining");
                printf("\n 2. insert at End");
                printf("\n 3. insert at Specific");
                printf("\n 4. Display the linked list");
                printf("\n 0. Exit");
                printf("\n Enter yout choice::");
                scanf("%d",&opt);
                switch(opt)
                {
                           case 1:   printf("Enter number to b");
                                     scanf("%d",&no);
                                     insertAtBegin(no);
                                     break;
                           case 2:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     insertAtEnd(no);
                                     break;
                           case 3:   printf("Enter number to b inserted::");
                                     scanf("%d",&no);
                                     printf("Enter position::");
                                     scanf("%d",&pos);
                                     insertAtPos(no,pos);
                                     break;
                           case 4:   Display();
                                     break;
                           case 5:   exit(0);
                           default:  printf("invalid option");
                                     break;
                };
                printf("\nwant to continue,(PRESS y for YES:::)");
                scanf("%s",&option);
                }while(option=='y');
                getch();
                }

void insertAtBegin(int no)
{
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;
     if(start!=NULL)
     {
                 node->next=start;
                 start=node;
     }
     else
     {
        start=temp=node;
        node->next=NULL;
     }
}

void insertAtEnd(int no)
{
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;
     node->next=NULL;
     if(start!=NULL)
     {
                 temp->next=node;
                 temp=node;
     }
     else
     {
        start=temp=node;
     }

}

void insertAtPos(int no, int pos)
{
     int i;
     if(pos==1)
     {
        insertAtBegin(no);
        return;
     }
     temp=start;
     printf("%d",temp->num);
     node=(NODE *)malloc(sizeof(NODE));
     node->num=no;

     for(i=1;i<pos-1;i++)
     temp=temp->next;
     node->next=temp->next;
     temp->next=node;
}

void Display()
{
                temp=start;
                printf("\ndisplay the linked list\n");
                while(temp->next!=NULL)
                {
                           printf("\n%d",temp->num);
                           temp=temp->next;
                }
                printf("\n%d",temp->num);
}

So, you are new to programming, yet you have all of this knowledge - and use html with it ? 'brother' , you shouldn't beg people to solve your problems, you will learn more from correcting it yourself anyway.

i think you are not being exited out of your program
if its the problem change the line

printf("\n 0. Exit");

to

printf("\n 5. Exit");

if the problem with your program is that u are not being exited after you press 0 then change the line

case 5:   exit(0);

to

case 5:   exit(0);

you have mixed "case" in your code. If the code that you have posted is what you are trying to compile then consider the following changes:

first (as vinitmittal2008 suggested) change line no. 13 to match exactly what he said, and i repeat:

typedef struct LinkedList NODE;

observe "LinkedList" as opposed to "linkedlist"

Next, change line no. 11 to:

struct LinkedList *next;

observe, "next" as opposed to "Next".

Apart from this there is another "logical" error. Change the exit condition to your case '5' as have been suggested above.

Lastly, when you are trying to learn something new (which is very good), try to understand what you are learning. If you simply copy paste other's code you won't learn anything. Now that it compiles and everything...try to understand the working and come up with certain modification. (for eg, this code will crash if you have 3 nodes long linked list and you tried to insert at the, say, 6th position, using the insertAtPos() function). Try to solve this problem.

Happy coding...:)

its solved

@Ali5152: then marked this thread as "Solved"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.