Let's say that I have the following code in C that represents a stack :
#define MAX 1000
int arr[MAX];
static int counter = 0;
isstackempty()
{
return counter <= 0;
}
void push(int n)
{
if (counter >= MAX) {
printf("Stack is full. Couldn't push %d", n);
return;
}
arr[counter++] = n;
}
int pop(int* n)
{
if(isstackempty() || n == 0) {
printf("Stack is empty\n");
return 0;
}
*n = arr[--counter];
return 1;
}
The above code is in a stack.c
file and the function prototypes are in a header.
Now, coming from a C# and OO background, if I would want to separate stack
s to use in my application, in an OO language I would create two instances. But in C, how do you handle such a scenario?
Say I want to use two separate stack
s in my C code...with the above code, how would I go about it?