title: Inputting an arithmatic statement in c and return the value
body: <p>(I am very bad at inputting/processing strings in <code>C</code>. Hope this question will teach me a lot.)</p>
  
  <p>I am trying to make a function that will input an arithmatic string from <code>stdin</code>, e.g <code>23 + 45 * 6 - 5</code>, and return the value.</p>
  
  <p>There are multiple strings, entered one after another, and can be of any length and the operator precedence doesn't matter, i.e., it processes string sequentially.  </p>
  
  <p>The problems that I faced are :-</p>
  
  <ol>
  <li><code>\n</code> from previous string is also considered a string.So if I input 3 strings , it will actually be 6, 3 strings and 3 <code>\n</code>.</li>
  <li>I used a char pointer and used <code>char * input; scanf(" %s",input);</code>, but in addition to above problem, I also get segmentation fault, which I guess is due to missing <code>\0</code>.</li>
  </ol>
  
  <p>My question is forget what mess I did, what would you have done or what's the best way to handle string input in the above scenario. A dummy code is sufficient.Thanks. </p>
  
  <p><strong>What I was doing</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      int t; //no of test cases
      char input;
      scanf("%d",&amp;t);
      while(t--)
      {
          while((input=getchar())!='\n')
          {
              //use switch to identify char and follow appropriate action 
              printf("%c\n",input );
          }
      }
      return 0;
  }
  </code></pre>