How to stop program from running? : <p>I included three break; in three different cases. I tested case 2, it stopped the program; however for case 1, it goes on and on even tho it has break;. I tried every possible solution to fix it. I couldn't figure it out.</p>

<p>how can I fix it?</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;



// self-referential structure                     
struct queueNode {                                   
   char data; // define data as a char            
   struct queueNode *nextPtr; // queueNode pointer
   struct queueNode *prevPtr;
}; // end structure queueNode                     

typedef struct queueNode QueueNode;
typedef QueueNode *QueueNodePtr;

// function prototypes
void printQueue( QueueNodePtr currentPtr );
int isEmpty( QueueNodePtr headPtr );
char dequeue( QueueNodePtr *headPtr, QueueNodePtr *tailPtr );
void enqueue( QueueNodePtr *headPtr, QueueNodePtr *tailPtr, 
   char value );
void instructions( void );
void reverse( QueueNodePtr currentPtr);

// function main begins program execution
int main( void )
{ 
   QueueNodePtr headPtr = NULL; // initialize headPtr
   QueueNodePtr tailPtr = NULL; // initialize tailPtr
   unsigned int choice; // user's menu choice
   char item; // char input by user

   instructions(); // display the menu
   printf( "%s", "? " );
   scanf( "%u", &amp;choice );

   // while user does not enter 3
   while ( choice != 3 ) { 

      switch( choice ) { 
         // enqueue value
         case 1:
            printf( "%s", "Enter a character: " );
            scanf( "\n%c", &amp;item );
            enqueue( &amp;headPtr, &amp;tailPtr, item );
            printQueue( headPtr );
            reverse( headPtr );
            break;
         // dequeue value
         case 2:
            // if queue is not empty

            if ( !isEmpty( headPtr ) ) { 

               item = dequeue( &amp;headPtr, &amp;tailPtr );
               printf( "%c has been dequeued.\n", item );
            } // end if

            printQueue( headPtr );
            reverse( headPtr );
            break;
         default:
            puts( "Invalid choice.\n" );
            instructions();
            break;
      } // end switch

      printf( "%s", "? " );
      scanf( "%u", &amp;choice );
   } // end while

   puts( "End of run." );
} // end main

// display program instructions to user
void instructions( void )
{ 
   printf ( "Enter your choice:\n"
           "   1 to add an item to the queue\n"
           "   2 to remove an item from the queue\n"
           "   3 to end\n" );
} // end function instructions

// insert a node in at queue tail
void enqueue( QueueNodePtr *headPtr, QueueNodePtr *tailPtr, 
   char value )
{ 
   QueueNodePtr newPtr; // pointer to new node
   QueueNodePtr currentPtr; 
   QueueNodePtr previousPtr; 

   newPtr = (QueueNodePtr)malloc(sizeof(QueueNode));

   if ( newPtr != NULL ) { // is space available 
      newPtr-&gt;data = value;
      newPtr-&gt;nextPtr = NULL;
      newPtr-&gt;prevPtr = NULL; 
      previousPtr = NULL; 
      currentPtr = *headPtr; 

      while(currentPtr != NULL &amp;&amp; value &gt; currentPtr-&gt; data)
      {
        previousPtr = currentPtr; 
        currentPtr = currentPtr-&gt;nextPtr; 
      }

      if(previousPtr == NULL)
      {
        newPtr-&gt;nextPtr = *headPtr; 

        if(*headPtr != NULL)
            (*headPtr)-&gt;prevPtr = newPtr; 
        *headPtr = newPtr; 
      }
      else
      {
        newPtr-&gt;prevPtr = previousPtr; 
        previousPtr-&gt;nextPtr = newPtr; 
        newPtr-&gt;nextPtr = currentPtr; 
            if(currentPtr != NULL)
                currentPtr-&gt;prevPtr = newPtr;
      }
   } // end if
   else {
      printf( "%c not inserted. No memory available.\n", value );
   } // end else
} // end function enqueue

// remove node from queue head
char dequeue( QueueNodePtr *headPtr, QueueNodePtr *tailPtr )
{ 
   char value; // node value
   QueueNodePtr tempPtr; // temporary node pointer
   QueueNodePtr currentPtr; 
   QueueNodePtr previousPtr;


   if(value == ( *headPtr )-&gt;data)
   {
        tempPtr = *headPtr;              
        *headPtr = ( *headPtr )-&gt;nextPtr;
        free(tempPtr);
        return value; 
   }
   else
   {
    previousPtr = *headPtr; 
    currentPtr = (*headPtr)-&gt;nextPtr; 

    while(currentPtr != NULL &amp;&amp; currentPtr-&gt;data != value)
    {
        previousPtr = currentPtr; 
        currentPtr = currentPtr-&gt;nextPtr; 
    }
    if(currentPtr !=NULL)
    {
        tempPtr = currentPtr; 
        previousPtr-&gt;nextPtr= currentPtr-&gt;nextPtr; 
        free(tempPtr);
        return value; 
    }
   }
   return '\0';
} // end function dequeue

// return 1 if the queue is empty, 0 otherwise
int isEmpty( QueueNodePtr headPtr )
{ 
   return headPtr == NULL;
} // end function isEmpty

// print the queue
void printQueue( QueueNodePtr currentPtr )
{ 
   // if queue is empty
   if ( currentPtr == NULL ) {
      puts( "List is empty.\n" );
   } // end if
   else { 
      puts( "The list is:" );

      // while not end of queue
      while ( currentPtr != NULL ) { 

         printf( "%c --&gt; ", currentPtr-&gt;data );
         currentPtr = currentPtr-&gt;nextPtr;
      } // end while

      puts( "NULL\n" );
   } // end else
} // end function printQueue

void reverse(QueueNodePtr currentPtr )
{
    QueueNodePtr tempPtr = NULL;

    while(currentPtr != NULL)
    {
        tempPtr = currentPtr; 
        currentPtr = currentPtr-&gt;nextPtr; 
    }
    printf("\nThe list in reverse is:");
    printf("NULL");

    currentPtr = tempPtr; 
    while(currentPtr != NULL)
    {
        printf(" &lt;-- %c", currentPtr-&gt;data);
    }
    printf("NULL\n");
}
</code></pre>
