title: stack around the variable 'PiglatinText' was corrupted
body: <pre><code>**Source.c**
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  
  #define SIZE 80
  #define SPACE ' '
  
  extern int isVowel(char);
  extern void initialiseString(char[]);
  extern int copyString(char[], char[], int);
  
  int main() {
      char originalText[SIZE] = {'\0'};
      char piglatinText[SIZE] = {'\0'};
      char firstChar[SIZE];
      int i, j, k, l, wordCount;
      wordCount = 1;
      i = j = k = l = 0;
  
      printf("Enter the text for which you want to generate the piglatin\n");
      gets(originalText);
  
      while (originalText[i] != NULL) {
          if (originalText[i] == SPACE) {
              if (originalText[i + 1] != SPACE) {
                  wordCount++;
              }
          }
          i++;
      }
  
      printf("Total words in the string are %i\n", wordCount);
  
      // piglatin Generator
      for (i = 0; i &lt; wordCount; i++) {
          initialiseString(firstChar);
          l = 0;
  
          while (!isVowel(originalText[j]) &amp;&amp; (originalText[j] != SPACE) &amp;&amp; (originalText[j] != NULL)) {
              firstChar[l++] = originalText[j++];
          }
  
          if (isVowel(originalText[j])) {
              while ((originalText[j] != SPACE) &amp;&amp; (originalText[j] != NULL)) {
                  piglatinText[k++] = originalText[j++];
              }
  
              k = copyString(piglatinText, firstChar, k);
          } else {
              firstChar[l] = '\0';
              k = copyString(piglatinText, firstChar, k);
          }
  
          piglatinText[k++] = 'a';
          piglatinText[k++] = ' ';
          j++;
      }
  
      printf("The piglatin text\n");
      puts(piglatinText);
  
      getch();
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p><strong>Functions.c</strong></p>
  
  <pre><code>#include &lt;string.h&gt;
  
  int isVowel(char ch) {
      if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
          ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
          return 1;
      }
  
      return 0;
  }
  
  void initialiseString(char string[]) {
      int i;
      int len;
      len = strlen(string);
      i = 0;
  
      while (i &lt;= len) {
          string[i++] = '\0';
      }
  
      return;
  }
  
  int copyString(char stringOne[], char stringTwo[], int k) {
      int i;
      int len;
      len = strlen(stringTwo);
      i = 0;
  
      while (len &gt; 0) {
          stringOne[k++] = stringTwo[i++];
          len--;
      }
  
      return k;
  }
  </code></pre>
  
  <p>Here the main function is present in the Source.c file and all the functions used in Source.c file are defined in Functions.c file.</p>
  
  <p>Whenever I run this code, the originalText is encoded correctly but at the end the error <strong>stack around the variable 'PiglatinText' was corrupted</strong> is generated! I tried to find the error by debugging but was unable to find the error source.</p>