title: Creating a push() method for a singly linked list with two parameters
body: <p>I need to create the push method for a program that push an element into a stack.  I have created this <em>typedef</em>:</p>
  
  <pre><code>typedef struct node{
      int value;
      struct node *next;
  } Node;
  </code></pre>
  
  <p>With this snippet of code in my main:</p>
  
  <pre><code>Node *stackptr;
  stackptr = NULL;
  </code></pre>
  
  <p>This is where I have a problem and am not sure exactly what is going on - In my push method im not sure if I am returning the updated pointer to the top of the stack.  Im suppose to check if it is empty as well but I am going to get to that last.  Here is the push() function:</p>
  
  <pre><code>void push(Node *stkptr, int i){
     Node *temp;
     temp = malloc(sizeof(Node));
     temp-&gt;value = i;
     temp-&gt;next = *stkptr;
     return *stkptr = temp;
  }
  </code></pre>
  
  <p>Hope this makes some sort of sense what I am trying to get across.  Thanks for any advice you are able to give me.  Hope all is well.</p>
  
  <p>Last I am in need of fixing my int pop() function! I have to return the value of the node that was popped. I believe I am almost there - my compiler is still throwing errors. This is what I have so far:</p>
  
  <pre><code>int pop(Node** stkptr){
  Node *temp;
  temp = malloc(sizeof(Node));
  
  if((*stkptr) == NULL){
      fprintf(stderr, "The stack is empty. Pop is not allowed\n");
      return 0;
  }
  else{
      temp = *stkptr;
      stkptr = *temp;
  }
  return stkptr;
  free(temp);
  }
  </code></pre>
  
  <p>However, the compiler is throwing the error: 
  incompatible types when assigning to type ‘struct Node **’ from type ‘Node’</p>
  
  <p>warning: return makes integer from pointer without a cast</p>
  
  <p>Can someone please help me fix my problem! Thanks!</p>