Q:

Push, pop and display functions from one string to a stack

I'm trying to write a program where the user introduces an array numbers and alphabethic characters. Then the program reads the array, if he sees a number, the program should push that number into one stack. However, if he sees an alphabetical character, the last number pushed is popped.
So far I have this code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX 20

int top, i;
void push (double stack[], double x, int top)
{
stack[top] = x;
}
 int pop (double stack[])
{
    double x;
    stack [top]=x;
    return x;
}

void display (double stack[],int top)
{
    int i;
    printf ("\n The stack is: ");
        for (i=0; i<=top; i++)
         {
           printf ("%lf\n",stack[i]);
     }
}

void main()
{
int r;
int stack[10];
char array[10];
printf("introduce the numbers");
fgets(array,MAX,stdin);
int l;
r=strlen(array);
top=0;
for (l=0;l<=r;l++)
{
int n;
if (isdigit(array[l]))
 {
    push(stack,array[l],top);
    top=top+1;
 }

 if (islower(array[l]))
 {
        pop(stack);
        printf("you have popped %d", n);
        top=top-1;
 }
}
 display(stack,top);
}

For some reason the program does not work, if I introduce 22a the output is:
you have popped 4194432
The stack is: 50.00000
50.00000
I am particularly interested in how should I write the pop,push and display to make this program work. How can I do it?

A:

First off, your variable n, the value of which you're printing, is uninitialized and contains whatever garbage that was in the memory at the moment of its creation. 
Also, why are you printing it? I think you meant to say n = pop(stack);, right? Otherwise this printing is useless.
Throughout your code you're writing loops the wrong way: for (t=0; t<=threshold; t++). This code will make the loop run threshold + 1 times, but you obviously want only threshold, so do for (t=0; t<threshold; t++) instead.
You're also reading (fgets(array,MAX,stdin);) maximum twenty characters into your array, which can hold only ten characters.
To use strlen on an array, you need it to end with zero (null-terminator). In your code array is not necessarily initialized with zeros, so use memset(array, 0, 10); before using array:

Docs on memset
Tutorial on for loops
void main() is wrong
What to read to learn C

