I'm trying to make sure if my initialization stack function gets all the values enter by user, but right now my codes print out different values from the original values I enter. I use %d. Also, I'm working on different functions to work with the stack as such as pop, push, goes to top of stack, etc. Will it do work in do while loop? However, here is the initialization stack function
typedef struct stack
{
int* darr;
int size;
int top;
}stack;
stack * initStack(int elements)
{
stack *s;
s = (stack *)malloc(sizeof(stack));
s->darr = (int *)malloc(sizeof(int)*elements);
s->size = 0;
s->top = elements;
return s;
}
in the main ()
int main()
{
stack s;
int i;
printf("Hello user, please enter 10 different values to build your stack: \n");
for(i = 0; i < 10; i++)
{
scanf("%d", initStack(i));
}
printf("\nYou entered: \n%d\n\n", initStack(i));
return 0;
}