title: Segmentation fault (core dumped) runtime error in C
body: <p>Hi so I am new to C and just wrote my first program in the language and keep getting the segmentation fault error when I try to run it. I'm sure there are multiple small mistakes I have made throughout the code. I have gone through it and I can't figure out where my mistake is. Here is my code: </p>
  
  <pre><code>// $Id: crpn.c,v 1.1 2013-10-22 13:28:04-07 - - $
  
  #include &lt;assert.h&gt;
  #include &lt;libgen.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int exit_status = EXIT_SUCCESS;
  #define EMPTY (-1)
  #define SIZE 16
  
  typedef struct stack stack;
  struct stack {
     int top;
     int capacity;
     int size;
     double numbers[SIZE];
  };
  
  void bad_operator (const char *oper) {
     fflush (NULL);
     fprintf (stderr, "oper=\"%s\"\n", oper);
     fflush (NULL);
     exit_status = EXIT_FAILURE;
     printf("%s: invaild operator\n", oper);
  }
  
  void push (stack *the_stack, double number) {
     if (the_stack-&gt;size == the_stack-&gt;capacity) {
          printf("%a:stack overflow", number);
      }
     else {
          the_stack-&gt;numbers[the_stack-&gt;size++]=number;
      }
  }
  
  void do_binop (stack *the_stack, char oper) {
    if ((the_stack-&gt;top)&lt;1) {
          printf("oper=\"%c\":stack underflow\n", oper);
      }
     else {
          double right = the_stack-&gt;numbers[the_stack-&gt;size--];
          double left = the_stack-&gt;numbers[the_stack-&gt;size--];
          switch (oper) {
              case '+': push (the_stack, left + right); break;
              case '-': push (the_stack, left - right); break;
              case '*': push (the_stack, left * right); break;
              case '/': push (the_stack, left / right); break;
            }
          }
  }
  
  void do_print (stack *the_stack) {
     if (the_stack-&gt;top == -1) {
         printf("stack is empty\n");
      }
     else {
         int pos;
         for (pos = 0; pos &lt;= the_stack-&gt;top; ++pos) {
            printf("%a\n",the_stack-&gt;numbers[pos]);
     }
   }
  }
  
  void do_clear (stack *the_stack) {
     the_stack-&gt;top = -1;
  }
  
  void do_operator (stack *the_stack, const char *oper) {
     switch (oper[0] ) {
           case '+': do_binop (the_stack, '+'); break;
           case '-': do_binop (the_stack, '-'); break;
           case '*': do_binop (the_stack, '*'); break;
           case '/': do_binop (the_stack, '/'); break;
           case ';': do_print (the_stack);      break;
           case '@': do_clear (the_stack);      break;
           default : bad_operator (oper);       break;
     }
  }
  
  int main (int argc, char **argv) {
     if (argc != 1) {
        fprintf (stderr, "Usage: %s\n", basename (argv[0]));
        fflush (NULL);
        exit (EXIT_FAILURE);
     }
     stack the_stack;
     the_stack.top = EMPTY;
     char buffer[1024];
     for (;;) {
        int scanrc = scanf ("%1023s", buffer);
        if (scanrc == EOF) break;
        assert (scanrc == 1);
        if (buffer[0] == '#') {
           scanrc = scanf ("%1023[^\n]", buffer);
           continue;
        }
        char *endptr;
        double number = strtod (buffer, &amp;endptr);
        if (*endptr == '\0') {
           push (&amp;the_stack, number);
        }else if (buffer[1] != '\0') {
           bad_operator (buffer);
        }else {
           do_operator (&amp;the_stack, buffer);
        }
     }
     return exit_status;
  }
  </code></pre>