-1

I have problem in push function. My code is

struct stack_t{
    DATA_TYPE size;
    DATA_TYPE top;
    DATA_TYPE *arr;
}    
void push(stack_t* s, DATA_TYPE item) {
        if (is_full(s) == true ) {
            exit(1);
        }
        else {
            s->arr[++(s->top)] = item;
        }
    }

The line s->arr[++(s->top)] = item; has the error.(Bold part especially) It says read access error. I found that I have to write my code in address but I write my code in value. But I have no idea how to change my code. How I can express Struct array address?

yoon-seul
  • 13
  • 3
  • What is `stack_t`? What is `DATA_TYPE`? How is the function called? etc. Please provide complete code as a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and also give the *exact* error. – kaylum Jul 19 '21 at 04:02
  • I edited Sorry for unconvinence – yoon-seul Jul 19 '21 at 04:05
  • 1
    That is still not complete code. It needs to be code that anyone can copy exactly as shown to run it and see the problem. And you still have not provided the exact error. Please read the link that explains what needs to be provided: [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – kaylum Jul 19 '21 at 04:05

1 Answers1

0

first, size should be an int value instead of DATA_TYPE. Then in push, you should use s->arr[++(s->size)]. But still, you need to make sure the stack and the arr are properly initialized/allocated. And I wonder how you want to implement your pop() and how top will act.

lei zhou
  • 1
  • 2