title: How do I add randomly generated characters to a string in C?
body: <p>I'm trying to create a program that solves the Countdown words game which involves asking for a proportion of vowels and consonants. I want to add random characters to a string that will be passed to a permutation function. </p>
  
  <p>When I run the following program and select "C" I get the error "l buffer is too small &amp;&amp; 0 c" and the program crashes.</p>
  
  <p>Typing "V" will give the error "Invalid!EIOU" without crashing.</p>
  
  <p>How can I create this random string with vowel and consonant amounts dictated by the user's input? </p>
  
  <p>Should this be done as an array instead?</p>
  
  <pre><code>// April16Assignment.cpp : Defines the entry point for the console application.
  //
  
  #include "stdafx.h"
  #include &lt;stdlib.h&gt;
  #include &lt;string&gt;
  using namespace std;
  
  const char * main() {
  
      char type, letters[10] = { };
      char vowels[6] = { 'A', 'E', 'I', 'O', 'U' };
      char consonants[21] = { 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z' };
      int i, k, v, l, c;
  
      for (i = 0; i &lt; 9; i++) {
          printf("Vowel or consonant? (V/C)\n");
          scanf_s("%c", &amp;type);
  
          if (type == 'V')
              for (k = 0; k&lt;1; k++) {
                  v = (rand() % 5);
                  strcat_s(letters, &amp;vowels[v]);
  
              }
          if (type == 'C')
              for (l = 0; l&lt;1; l++) {
                  c = (rand() % 21);
                  strcat_s(letters, &amp;consonants[c]);
  
              }
          else
              printf("Invalid!");
          break;
      }
  
      printf("%s", letters);
      return letters;
  }
  </code></pre>