Push and Pop function

Im trying to replicate the push and pop functions using integers and an int array. However Im having trouble with finding the size of the array in the push function. How would I find the size or ‘push’ a new value into the array

typedef int data_t;
int
main(int argc, char **argv){
int *S, i;

    S = malloc(10*sizeof(int));
    S = NULL;
    push(1,S);
    push(3,S);

    for(i = 0; S[i]; i++){
        printf("%dn",S[i]);
        }
    return 0;
}

void
push(data_t n,int *S ){
    int size = 0, i = 0;

    if (S == NULL){
        S[0] = n;
    }
    else{
        while(S[i] != NULL){
            size++;
            i++;
        }
        S[size] = n;
    }
}


Source: c#

Leave a Reply