title: Printing a string backwards in C with scanf
body: <p>I am trying to print my string backwards in c and I just can't seem to get it working with whitespaces. I am aware that if there is any whitespace after the last returned character in the scanf function that it will terminate because there is no existing characters left to scan in from the string entered. Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define MAXLETTERS 20
  
  void readStringBackwards();
  
  main()
  {
  readStringBackwards();
  }
  
  
  void readStringBackwards()
  {
  
  
  
  printf("Please enter a string of up to 20 characters in length:\n ");
  char str[20];
  scanf("%s", str);
  int i;
  int stringlength = strlen(str);
  
  if (stringlength &gt; MAXLETTERS)
  {
      printf("The string length is too long!");
  }
  else
  {
      for( i = stringlength-1; i &gt;= 0; i--){
  
          printf("%c ", str[i]);
  
      }
  
  }
  
  
  
  }
  </code></pre>
  
  <p>Essentially the program is supposed to accept up to 20 characters, and print the string backwards. I have been searching for information on scanf and how it works, but its been pretty hard to find a direct answer. Any tips are appreciated. Right now all I will get is the first word that I type in reverse. The other characters after an space are skipped and not stored within the array.</p>