I am trying to write a program to copy the contents of one stack to another. The following is the code that I came up with. It give me some syntax errors but I cannot seems to see any. Can anyone help ?

//Defining what libraries should be included.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>


typedef struct node
{
   void* dataPtr;
   struct node* link;
}STACK_NODE;

typedef struct
{
   int count;
   STACK_NODE* top;
}STACK;

STACK* createStack (void)
bool pushStack (STACK* stack, void* dataInPtr);
void* popStack (STACK* stack);
bool emptyStack (STACK* stack);
STACK* destroyStack (STACK* stack);

int main(void)
{
    STACK* sourceStack;
    STACK* destinationStack;
    STACK* tempStack;
    int dataInPtr;

    sourceStack = createStack();
    destinationStack = createStack();
    tempStack = createStack();

    //Tells the user how to exit the program.   
   printf("Enter '-1' to stop the program\n"); 
   printf("Enter a number :");
   scanf("%d",dataInPtr);

   while (dataInPtr != -1)//Beginning of while loop
{  
   dataPtr = (int*)malloc(sizeof(int));
   *dataPtr = dataInPtr;
   pushStack(STACK* sourceStack,dataPtr);
   printf("Enter a number :");
   scanf("%d",dataInPtr);
} 
    while (!emptyStack(sourceStack))
    {
          popStack(STACK* sourceStack);
          pushStack(STACK* tempStack, int dataPtr);
    }
    while (!emptyStack(tempStack))
    {
          popStack(STACK* tempStack);
          pushStack(STACK* destinationStack, int dataPtr);
    }
    destroyStack(STACK* sourceStack);
    destroyStack(STACK* tempStack);

    system("PAUSE");
    return 0;
}

//Create Stack
STACK* createStack (void)
{
       STACK* stack;

       stack = (STACK*)malloc(sizeof(STACK));
       if(stack)
       {
          stack->count = 0;
          stack->top = NULL;
       }
       return stack;
}


//Push Stack
bool pushStack (STACK* stack, void* dataInPtr)
{
     STACK_NODE* newPtr;

     newPtr = (STACK_NODE*) malloc(sizeof(STACK_NODE));
     if(!newPtr)
     return false;

     newPtr->dataPtr = dataInPtr;

     newPtr->link = stack->top;
     stack->top = newPtr;
     (stack->count)++;

      return true;
}

//Pop Stack
void* popStack (STACK* stack)
{
      void* dtaOutPtr;      
      STACK_NODE* temp;

      if(stack->count == 0)
         *dataOutPtr = NULL;
      else
      {
         temp = stack->top;
         dataOutPtr = stack->top->dataPtr;
         stack->top = stack->top->link;
         free(temp);
         (stack->count)--;
      }
      return dataOutPtr;
}

//Empty Stack
bool emptyStack (STACK* stack)
{
     return (stack->count == 0);
}

//Destroy Stack
STACK* destroyStack (STACK* stack)
{
       STACK_NODE* temp;

       if(stack)
       {
          while(stack->top != NULL)
          {
             free (stack->top->dataPtr);

             temp = stack->top;
             stack->top = stack->top->link;
             free(temp);
          }
          free(stack);
       }
       return NULL;
}

Don't ask us to do that with a long "stack" of code without providing the compiler output with syntax errors and warnings.

Line 19 : ' ; ' missing

You are using dataPtr in line 43, while its a member of structure node.
There are other similar errors.

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.