Check for duplicate before adding into array, using pointers
<p>I have a global static Strings str[MAX] = { "aloha" , "behold", "donkey", "key", "joke", "none", "quack", "orange"};</p>

<p>The size here was randomly generated, for example if size = 3, it will print out "Behold", "donkey" and "none". Before adding into the array, i want to check if it is inside.
if "Behold", "donkey", "none" is inside the array, and if i get another word, "donkey", it will reject and go back to loop and generate another one, thus i use i--</p>

<p>I'm not sure where went wrong, i hope someone can enlighten me.</p>

<p>Thanks. Here's the code.</p>

<pre><code>typedef char* Strings;

function example (Strings *s, int size)
{
    char *q;

    bool check;

    q = new char[MAX];

    *s = &amp;q[0];
    for (int i = 0; i &lt; size; i++)
    {
        k = rand () % 8;
        if (*s == '\0')
            *s = Str[k];
        else
        {
            check = compare (s, Str[k]);

            if (check == 1)
                *s = Str[k];
            else
                i--;
        }
        ++s;
    }

    cout &lt;&lt; endl;
}

bool compare (Strings *s, char *str)
{
    while (*s != '\0')
    {
        if (strcmp (*s, Str))
            return true;
        else
            return false;
        ++s;
    }
}
</code></pre>
