title: Why isn't my coding reading the \n
body: <p>I was writing a code that takes a sentence and reverses it, as an exercise. Here's what I wrote:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      char a, sentence[100], sign;
      char *c = sentence; 
  
      printf("Enter a sentence: ");
  
      while ( (a = getchar()) != '\n' ) 
      {
          if ( a == '?' || a == '!' || a == '.')
          {
              sign = a;
              break;
          }
  
          *c = a;
          c++;
      }
  
      for (char *d = c; d &gt;= sentence; d--)
      {
          if ( (d == sentence) &amp;&amp; (*d != ' ') )
          {
              for (char *a = d; a &lt; d + 99; a++)
              {
                  if ( (*a == ' ') || (*a == '\n')) //code isn't reading the \n
                  {
                      break;
                  }
                  else
                      printf("%c", *a);
              }
          }
  
          if ( (*d == ' ') &amp;&amp; (d != c) &amp;&amp; (d != sentence + 99) )  
          {
              for (char *a = d+1; a &lt;=  c; a++)
              {
                  if ( (*a == ' ') || (a == c))
                  {
                      printf(" ");
                      break;
                  }
                  else
                      printf("%c", *a);
  
              }
          }       
      }
      printf("%c\n", sign);
  
      return 0;
  }
  </code></pre>
  
  <p>It works fine when I input a sentence with spaces in it:</p>
  
  <blockquote>
    <p>Enter a sentence: This is a sentence<br>
       sentence a is This</p>
  </blockquote>
  
  <p>However if I input a string with no spaces, like this:</p>
  
  <blockquote>
    <p>Enter a sentence: Thisisasentence</p>
  </blockquote>
  
  <p>I get an output with what was originally entered ('Thisisasentence'), followed by a lot of gibberish output. From what I understand, this is because the code doesn't go into the <code>if ( (*a == ' ') || (*a == '\n')</code> condition. </p>
  
  <ul>
  <li>Why isn't the compiler reading the '\n' </li>
  </ul>