Start New Discussion within our Software Development Community

I want to take out words that reoccur in array1 and put them in array3.
(so in array 3 there would be only distinct values)
the problem is.. i dont understand how the count2 value can reach so high. (over 300) but should be 20 maximum.

for(i=0; i<count;i++){
                   //put the first value in array3
                   strcpy(array3[0], array1[0]); 
                      //if they are same
                      if(strncmp(array1[i], array3[j], 3)==0){
                           strcpy(array3[count2], array1[i]);

Because every time a word from array1 does not match a word int array3, it's added to array3.

So, if you have 4 words in array3, and the current word in array1 matches none of the words, the word will be added 4 times to array3. You now have 8 words in the array.

Look closer at how your loop and IF statements works. You only want to add the word after you've looked at all the words in array3

This question has already been answered. Start a new discussion instead.