That is a stack program - I tried to change from integers to characters so when you enter a single char of a-z. I ran the program then it displayed shown below:
Enter a number: <EOF> to stop: a
Enter a number: <EOF> to stop: Enter a number: <EOF> to stop: b
Enter a number: <EOF> to stop: Enter a number: <EOF> to stop: c
Enter a number: <EOF> to stop: Enter a number: <EOF> to stop: d
Enter a number: <EOF> to stop: Enter a number: <EOF> to stop: e
Enter a number: <EOF> to stop: Enter a number: <EOF> to stop: ^Z
The list of numbers reversed:
e
d
c
b
a
Press any key to continue . . .
Why did it appear the output twice "Enter a number: <EOF> to stop: Enter a number: <EOF> to stop:"?
The code is below:
#include <stdio.h>
#include <stdbool.h>
#include "stacksADT.h"
int main (void)
{
int done = false;
char* dataPtr;
STACK* stack;
stack = createStack ();
while (!done)
{
dataPtr = (char*) malloc (sizeof(char));
printf ("Enter a number: <EOF> to stop: ");
if ((scanf ("%c" , dataPtr)) == EOF
|| fullStack (stack))
done = true;
else
pushStack (stack, dataPtr);
}
printf ("\n\nThe list of numbers reversed:\n");
while (!emptyStack (stack))
{
dataPtr = (char*)popStack (stack);
printf ("%3c\n", *dataPtr);
free (dataPtr);
}
destroyStack (stack);
system("pause");
return 0;
}