title: Evaluating math expression given in character array
body: <p>So, I have an input expression which is of the form 
  ....?5+8 ...</p>
  
  <p>I need to parse this and evaluate the result. Since I know that the expression starts after the ? and ends with a ' ',  I tried this:</p>
  
  <pre><code>int evaluate(char *buffer){
  char exp[50];
  while(buffer[i] != '+' || buffer[i] != '-' || buffer[i] != '*' || buffer[i] != '/'){
      exp[j] = buffer[i];
      i++;
      j++;
  }
  exp[j] = '\0';
  int number1 = atoi(exp);
  
  char operation = buffer[i];
  i++;
  j = 0;
  while(buffer[i] !=' '){
      exp[j] = buffer[i];
      i++;
      j++;    
  }
  exp[j] = '\0';
  int number2 = atoi(exp);
  
   switch(operation)....
   }
  </code></pre>
  
  <p>where j is initialized from 0 and i is initialized to the position after ?.</p>
  
  <p>The function is called using evaluate(buffer);</p>
  
  <p>However, I keep getting the error Segmentation Fault (core dumped).</p>
  
  <p>EDIT
  Here's the debugger output</p>
  
  <pre><code>82                              evaluateExp(buffer);
  (gdb) next
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000401257 in evaluateExp (
  buffer=0x603010 "GET /calculate.html?555+777 HTTP/1.1\nHost:localhost\n\n") at webserver.c:108
  108             while(buffer[i] != '+' || buffer[i] != '-' || buffer[i] != '*' || buffer[i] != '/'){
  (gdb) next
  
  Program terminated with signal SIGSEGV, Segmentation fault.
  The program no longer exists.
  </code></pre>
  
  <p>Any Ideas?</p>