title: Writing a push and pop in c
body: <p>Original Q: I'm trying to create this calculator in C for a project. I got the math functions working, but not I am stuck on how to handle the push an pop. Can somebody help me get started? I know what push and pop are supposed to do from java, but I am not sure how to use them without using nodes or an array.   </p>
  
  <p>My includes and stack struct:</p>
  
  <pre><code>#include &lt;assert.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #include "stack.h"
  #include "debug.h"
  
  #define DEFAULT_CAPACITY 16
  
  struct stack {
     size_t capacity;
     size_t size;
     stack_item *data;
  };
  </code></pre>
  
  <p>My attempted push and pop:</p>
  
  <p><strong>UPDATED</strong></p>
  
  <pre><code>    void push_stack (stack *this, stack_item item) {
     if (full_stack (this)) realloc_stack (this);  
     this-&gt;data[this-&gt;size++]=item;
  }
  
  stack_item pop_stack (stack *this) {
     assert (! empty_stack (this)); 
     if(this-&gt;data == NULL){
       fprintf(stderr, "fail");}
     else{
      stack_item tempPop = this-&gt;data[this-&gt;size--];   
      return tempPop;}
  }
  </code></pre>
  
  <p>Updated Q: This is now what I am doing for my push/pop method. I am getting no warnings and no errors, but when I run it, it seg faults after it should pop. </p>
  
  <p>My new question is, does it appear that something I am doing in this block of code is causing my seg fault?</p>