title: Parsing the string for a calculator in C Programming
body: <p>I am building a scientific calculator.</p>
  <p>The functioning of this calc will go in this way...</p>
  <ol>
  <li>User will put scientific expressions like <code>cos(45)</code>.</li>
  <li>The calculator will contain 3 supported functions like <code>sin, cos, tan</code> for now.</li>
  <li>a while loop will detect <code>sin</code> and will store it in <code>container[5]</code>.</li>
  <li>A function <code>int match(char* exp)</code> will take string <code>cos</code> from <code>container[5]</code> and will search  if it gets matched with any element in <code>supportedFn[3]</code>.</li>
  <li>If match is found, the string <code>sin</code> from <code>container[5]</code> will get transferred to the position 0 of <code>char* tokens[30]</code>.  (function setting Tokens[30] is  not implemented).</li>
  <li>The <code>container[5]</code> will <strong>emptied</strong> by using function <code>void makeBlank(char* box)</code> so that <code>container[5]</code> can be used for storing detected strings like <code>multiple digit numbers</code>, <code>(</code>, <code>)</code>, etc.</li>
  </ol>
  <p>Later on the completed token array will look like <code>tokens[30] = {&quot;cos&quot;, &quot;(&quot;, &quot;45&quot;, &quot;)&quot;}</code>.</p>
  <p><strong>So I am facing problem in <code>match()</code> function I am using for loop inside it</strong></p>
  <p>But its not giving correct return values pls help. How do I implement <code>match()</code> properly so that it returns 1 if it finds <code>cos</code> at any position in <code>supportedFn[3]</code>?</p>
  <p>Below is my code...</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  char* supportedFn[3]= {&quot;sin&quot;, &quot;cos&quot;, &quot;tan&quot;};
  
  char* expression = &quot;cos(45)&quot;;    // Entered by the user
  
  char container[5];        // array to store functions entered by user (Ex. cos)
  
  
  
  
  // Function to make container blank after detecting
  
  void makeBlank(char* box){       
      int i = strlen(box);
      while(box[0] != '\0'){
          box[i] = '\0';
          i--;
      }
  }
  
  int match(char* exp){
      for(int i=0; i&lt;3; i++){
          if(strcmp(exp, supportedFn[i]) == 0){
              break;
              return 1;
          }
          else{
              return 0;
          }
      }
  }
  
  
  
  
  int main(){
      
      // For storing string function like sin, cos, tan
  
      int i = 0;
      while(expression[i] != '\0'){
          if(isalpha(expression[i])){
              container[i] = expression[i];
              i++;
          }
          else{i++;}
      }
  
      printf(&quot;%d is the value\n&quot;, match(container)); //Not getting proper result
  
  </code></pre>
  <p><code>Not able to implement further if match() is not working properly</code></p>