Solved

dll

Posted on 2004-09-28
5
257 Views
Last Modified: 2010-04-01
hi
 experts

    i have a runtime error in my program in c++.it is a very small program but not able to debug it.there is the source code.

#include <iostream>
using namespace std;
int insert();
int print();
main()
{
   struct node
   {
         int info;
         node *next;
   };

      node* head=NULL;
      node* temp=NULL;
      node* temp1=NULL;
      head=new node;
      head->next=NULL;
      int c;
      cout<<"1--->insert."<<endl<<"2--->delete."<<endl<<"3--->print."<<endl<<"4--->Exit."<<endl;
      cout<<"Enter the choice --";
      cin>>c;
      switch(c)
      {
      case 1:insert();
            {
              int x;
            cout<<"Enter the data to be insterted __ ";
              cin>>x;
              if(head->next==NULL)
                head->info=x;
              else
                  {
                  temp=head;
                  while(temp->next!=NULL)
                    temp=temp->next;
                  if(temp->next==NULL)
                    {
                     temp1=new node;
               temp1->info=x;
                     temp->next=temp1;
                     temp1->next=NULL;
                    }
                  }
            }
            break;
//      case 2:del();break;
    case 3:print();
            {
      if(head==NULL)
            cout<<"No elements to display";
      else
      {
      temp=head;
       do
         {
               cout<<temp->info<<"->";
               temp=temp->next;
         }while(temp->next!=NULL);
         }
}
break;
      case 4:exit(0);break;
      default:cout<<"Entered wrong choice";
      }
      return 0;
}
 

please help me asap.
0
Comment
Question by:rajashekar2004
5 Comments
 

Accepted Solution

by:
amjedmsa earned 20 total points
ID: 12177039
why int insert();

here a modifiyed one it works

#include <iostream>

using namespace std;


int insert;
int print;
main()
{
   struct node
   {
        int info;
        node *next;
   };

     node* head=NULL;
     node* temp=NULL;
     node* temp1=NULL;
     head=new node;
     head->next=NULL;
     int c;
     cout<<"1--->insert."<<endl<<"2--->delete."<<endl<<"3--->print."<<endl<<"4--->Exit."<<endl;
     cout<<"Enter the choice --";
     cin>>c;
     switch(c)
     {
     case 1:insert;
          {
             int x;
            cout<<"Enter the data to be insterted __ ";
             cin>>x;
             if(head->next==NULL)
              head->info=x;
             else
               {
                temp=head;
                while(temp->next!=NULL)
                 temp=temp->next;
                if(temp->next==NULL)
                 {
                  temp1=new node;
               temp1->info=x;
                  temp->next=temp1;
                  temp1->next=NULL;
                 }
               }
          }
          break;
//     case 2:del();break;
    case 3:print;
          {
     if(head==NULL)
          cout<<"No elements to display";
     else
     {
      temp=head;
       do
        {
             cout<<temp->info<<"->";
             temp=temp->next;
        }while(temp->next!=NULL);
        }
}
break;
     case 4:exit(0);break;
     default:cout<<"Entered wrong choice";
     }
     return 0;
}
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12177675
Maybe you want that:

#include <iostream>
using namespace std;

struct node
{
   int info;
   node *next;
};

void insert(node*& head);
void print(node* head);
void deleteAll(node* head);

int main()
{
   
    node* head= NULL;
   
    while (true)
    {
        int c;
        cout<<endl<<"1--->insert."<<endl<<"2--->delete."<<endl<<"3--->print."<<endl<<"4--->Exit."<<endl;
        cout<<"Enter the choice --";
        cin>>c;
       
        switch(c)
        {
        case 1:
            insert(head);
            break;
            //     case 2:del();break;
        case 3:
            print(head);
            break;
        case 4:
            deleteAll(head);
            return 0;
        default:
            cout<<"Entered wrong choice"<<endl;
            break;
        }
    }
    return 1;
}


void insert(node*& head)
{  
    node* temp;
    node* temp1;
    int x;
    cout<<"Enter the data to be inserted __ ";
    cin>>x;
    if(head==NULL)
    {
        head = new node;
        head->next = NULL;
        head->info = x;
        return;
    }
    temp=head;
    while(temp->next!=NULL)
        temp=temp->next;
    temp1=new node;
    temp1->info=x;
    temp->next=temp1;
    temp1->next=NULL;
}

void print(node* head)
{
    if(head==NULL)
        cout<<"No elements to display";
    else
    {
        node* temp=head;
        do
        {
            cout<<temp->info<<"->";
            temp=temp->next;
        }
        while(temp !=NULL);
    }
}


void deleteAll(node* head)
{
    node* temp = head;
    node* temp1;
   
    while (temp != NULL)
    {
        temp1 = temp->next;
        delete temp;
        temp = temp1;
    }
}

Regards, Alex
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Prototype for MessageDlg in Embacadero XE 2 2 39
Excel/Word Add-in in what language? 5 119
mixing C++ & C# in Vis Studio 2013 7 178
Embarcadero C++ Builder XE2 TDateTime 8 72
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question