Iam trying to run this program for a very long time but i dont know why again and again segmentation fault error is coming (iam running this program on vs code and my OS is LINUX)
#include <stdio.h>
#include <stdlib.h>
struct stack
{
int size;
int top;
int *arr;
};
int isEmpty(struct stack *ptr)
{
if (ptr->top == -1)
{
return 1;
}
else
{
return 0;
}
}
int isFull(struct stack *ptr)
{
if (ptr->top == ptr->size - 1)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
struct stack *s;
s->size = 80;
s->top = -1;
s->arr = (int *)malloc(s->size * sizeof(int));
// Pushing an element manually
s->arr[0] = 7;
s->top++;
// Check if stack is empty
if (isEmpty(s))
{
printf("The stack is empty");
}
else
{
printf("The stack is not empty");
}
return 0;
}
please solve this error because iam stuck at this error and i dont know why this error is coming