title: array delete itself the first 3 char in C
body: <p>I have this data struct:</p>
  <pre><code>struct WordCounter
  {
    char *word;
    int word_count;
    struct WordCounter *pNext;                        /* Pointer to the next word counter in the list */
  };
  </code></pre>
  <p>I need it to memorize the words read from a file and how many times they occur. This struct has got these functions:</p>
  <pre><code>int giveCounter (struct WordCounter *pCounter){   // give the occurrence of the current word in the linked list
      int tempcount = pCounter -&gt; word_count;
     return tempcount;
      
  }
  
  int lengthOfCurrentWord(struct WordCounter *pWordCounter) // length of the current string
  {
      
      return strlen(pWordCounter-&gt;word)+1;  // for the null terminator string 
  }
  
  char* giveWord(struct WordCounter *pWordcounter){  // return current word of the linked list
      return pWordcounter-&gt;word;
  }
  </code></pre>
  <p>What I should do, is to take all the words in the list and put them into an array that can hold them all where each word is separated by a terminator.
  The code is this and after i explain where is the problem:</p>
  <pre><code>pCounter = pStart; // go to the first element in the linked list
  num_car=0;  // in total how much character in all words
  while(pCounter != NULL){
      num_car += lengthOfCurrentWord(pCounter);
      pCounter = pCounter -&gt; pNext;
  }
  printf(&quot;total number of chars in all words is: %d \n &quot;, num_car);
  </code></pre>
  <p>Ok now we have the dimension of the big array that have to save all words separated by a terminator.</p>
  <pre><code>char *exactly_word; // im forced to initialize like this and after i can  give the exactly number of elements
  exactly_word = malloc(sizeof(char)*num_car); // The big array
  memset(exactly_word,0,num_car);
  </code></pre>
  <p>Let's start to copy the word in the linked list into the big array:</p>
  <pre><code>char wordy[100] = {0}; // an array for the temp word
  pCounter = pStart;  // go to the first element
  int indice = 0;   // used for loop through single word
  int indice_parole = 0;  // It is used to indicate in which position of the large array to insert the character
  for(int x=0; x&lt;readed_nd_word;x++){   // readed_nd_words is the number of element in the linked list
      
      strcat(wordy,giveWord(pCounter));  // copy the current word into wordy array
      printf(&quot;WORDY: %s \n&quot;,wordy);      // yeah correct in each iteration
     
      while(wordy[indice]!= 0){
          printf(&quot;Character to add to exactly word: %c, at position: %d \n&quot;,wordy[indice],indice_parole);
          exactly_word[indice_parole] = wordy[indice]; // copy character
          indice_parole++;
          indice++;
      }
      
  
      pCounter = pCounter -&gt; pNext; // move into next word in the linked list
      memset(wordy,0,100);   // reset for a new word
      indice = 0;
      
      exactly_word[indice_parole] =0; // terminator for separating words
      printf(&quot;Terminator at position %d&quot;,indice_parole);
      indice_parole++; 
      
      
  }
  </code></pre>
  <p>Where is the problem? ok in the while loop exactly_word is filled in the right way, but after this code if i try to print exactly_word[0] the output is:&quot;&quot;, same for the position 1,2 of exactly_word. I can explain the problem better with an example, that i describe with the output:</p>
  <pre><code>words in the linked list:
    wut   1
    sut   1
    ov   1
    word   2
    ciao   1
    helo   1
    cor   1
    fal   1
    vermalen   1
  
  total number of chars in all words is: 43 (countered the terminator too)
  WORDY: wut 
  Character to add to exactly word: w, at position: 0
  Character to add to exactly word: u, at position: 1
  Character to add to exactly word: t, at position: 2
  terminator at position 3
  
  WORDY: sut 
  Character to add to exactly word: s, at position: 4
  Character to add to exactly word: u, at position: 5 
  Character to add to exactly word: t, at position: 6 
  terminator at position 7
  </code></pre>
  <p>For the rest of the words the output is correct, but after this code as i said if i print exactly_word[0] i got a &quot;&quot;, same as 1,2, instead at exactly_word[4] = &quot;s&quot; from the word sut.
  If i print all the array i have got this: &quot;sutovwordciaohelocorfalvermalen&quot;.</p>
  <p>P.s. the bug doesn't show up at every run, sometimes it does and sometimes it doesn't, when it doesn't show up exactly word is corrected. There is something like undefiend behaivor that i can't see? please help :(</p>