title: RPN Calculator in C
body: <p>Can someone please explain why I keep getting gibberish after I use strok() on myString? A picture of my output is at the bottom. I tried initializing every single element in myString to be a NULL character but my code still doesnt work :(</p>
  
  <p>Expected Output:</p>
  
  <p><a href="https://i.stack.imgur.com/sUe2W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sUe2W.png" alt="enter image description here"></a></p>
  
  <p>My Output :</p>
  
  <p><a href="https://i.stack.imgur.com/TiCa9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TiCa9.png" alt="enter image description here"></a></p>
  
  <pre><code>int main()
  {
      int i;
      char myString[60];
      char *token;
      float result;
      float x;
      float y;
      struct Stack myStack;
      StackInit(&amp;myStack);
  
  
      BOARD_Init();
  
      printf("\nWelcome to my RPN calculator.\n");
      printf("Enter floats and + - / * in RPN format: \n &gt;");
  
      for (i = 0; i &lt; sizeof (myString); i++) {
          myString[i] = '\0';
      }
  
      fgets(myString, sizeof (myString), stdin);
  
  
  
      token = strtok(myString, " ");
      while (token != NULL) {
          printf("%f\n", atof(token));
          token = strtok(NULL, " ");
  
          if (atof(token) != 0) {
              StackPush(&amp;myStack, atof(token));
          } else if (*token == '+') { // if token is addition
              StackPop(&amp;myStack, &amp;y);
              StackPop(&amp;myStack, &amp;x);
              result = x + y;
              StackPush(&amp;myStack, result);
  
          } else if (*token == '-') { // if token is subtraction
              StackPop(&amp;myStack, &amp;y);
              StackPop(&amp;myStack, &amp;x);
              result = x - y;
              StackPush(&amp;myStack, result);
          } else if (*token == '*') { // if token is multiplication
              StackPop(&amp;myStack, &amp;y);
              StackPop(&amp;myStack, &amp;x);
              result = x * y;
              StackPush(&amp;myStack, result);
          } else if (*token == '/') { // if token is division
              StackPop(&amp;myStack, &amp;y);
              StackPop(&amp;myStack, &amp;x);
              result = x / y;
              StackPush(&amp;myStack, result);
          }
  
      }
  
  
  
  
  while (1);
  </code></pre>
  
  <p>}</p>