title: I get weird symbols in the output in the terminal
body: <p>I am trying to make a program that would take a sentence from the user and reverse the order of the words while keeping the special characters ['.','?','!'] at the end.
  the problem I'm getting is that I get weird symbols after the last word and the special character.
  I am programming using C.
  I think it's because the last element printed is not a '\0'.
  but I don't know how to fix that.</p>
  <p>My code:</p>
  <pre><code>#include &lt;ctype.h&gt;
  
  #define N 200
  
  
  int main()
  {
      char arr[N] = { 0 }; 
  
      char* p, * q, mark = 0; 
      int c;
     
      p = arr;
      printf(&quot;Enter a sentence: &quot;);
      while ((c = getchar()) != '\n' &amp;&amp; p &lt; arr + N) 
      {
  
          if (c == '?' || c == '.' || c == '!') 
          {
              mark = c;
              break;
          }
          else 
              *p++ = c;
      }
      *p = '\0'; 
      printf(&quot;Reversal of sentence: &quot;);
      while (p &gt;= arr) 
      {
          while (*--p != ' ' &amp;&amp; p != arr); 
          if (p == arr) {q = arr;} 
          else {q = p + 1;} 
           
          
          while (*q != '\0' &amp;&amp; *q != ' ')
          { 
              printf(&quot;%c&quot;, *q++); 
          }
          if (p &gt;= arr) 
          {
              printf(&quot; &quot;);
          }
         
          
      }
      printf(&quot;%c&quot;, mark); 
      printf(&quot;\n&quot;);
      return 0;
  }
  </code></pre>