I can't push to stack. It is how my code looks like.
#include <stdlib.h>
#include <stdbool.h>
struct stos
{
int data;
struct stos *next;
};
bool add(struct stos *stack, int data)
{
struct stos *new_element = malloc(sizeof(struct stos));
if(NULL != new_element)
{
new_element -> data = data;
new_element -> next = stack;
stack = new_element;
return true;
}
return false;
};
int main()
{
struct stos stack;
add(&stack,2);
printf("Stack top data: %d\n",stosik.data);
}
Output: 69 Can someone help me to solve this problem? However if I change bool add to struct stosik *add it is working perfect. But I want to know how to change my code to bool or void type