title: Use scanf(), gets() or fgets() function?
body: <p>I am trying to encrypt a string by Caesar encryption, but it only works for one word (no spaces between characters). I would like to encrypt whole sentence. I have read here about getting white spaces from keyboard into a string by <code>gets()</code> or <code>fgets()</code>, but I cannot make it functional.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char** argv) {
      printf("Enter the shift: ");
      int shift,index,length;
      scanf("%d", &amp;shift);
  
      printf("Enter the string to encrypt: " );
      char string[1000];
      //gets(string);
      scanf("%s",string);
      //fgets(string,1000,stdin);
  
      char encrypted[strlen(string) + 1];
  
      for(index = 0, length = strlen(string); index &lt; length; index++ ){
          if (string[index]!=' ')
              encrypted[index] = 'A' + (string[index] -'A' + shift) % 26;
          else
              encrypted[index]=' ';
      }
      encrypted[ strlen(string)] = '\0';
  
      printf("%s\n", encrypted);
  
      return (EXIT_SUCCESS);
  }
  </code></pre>