Code work when debugging, but when it running the code crashed : <p>This code need to save friends in some array of array(pointer to pointer) and by the length of the names do realloc (build exactly dynamic place for the strings of each of them) and than prints the string and the length and free everything.
So the code work when i debugging but when I running it with CTR+f5 it's crashed after the fgets of the first string. also all the free loops and the free function doesn't work me here, but if remove it the debugging still work and the CTR+f5 still don't work. help someone?</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#define LENGTH 20

int main(void)
{
    int i = 0, j = 0,friends=0;
    char str[LENGTH];
    printf("Hello bro,how U doin'?\nTell me how many friends do you have?\n");
    scanf("%d",&amp;friends);
    char** friendBook = (char**)malloc(sizeof(char)*friends);
    if (friendBook)
    {
        getchar();
        for (i = 0; i &lt; friends; i++)
        {
            *(friendBook+ i) = malloc(LENGTH*sizeof(char));
        }
        for (i = 0; i &lt; friends; i++)
        {
            printf("Enter friend number: %d\n", i + 1);
            fgets(str, LENGTH, stdin);
            str[strcspn(str, "\n")] = 0;
            *(friendBook + i) = (char*)realloc(*(friendBook+i),(sizeof(char)*strlen(str)));        // dynamic memory for every string(name)
            if (*(friendBook + i))
            {
                strcpy(*(friendBook+i),str);
            }
        }
        for (i = 0; i &lt; friends; i++)
        {

            printf("Friend: %s\tLength of friend name %d\n", *(friendBook + i), strlen(*(friendBook + i)));
        }
    }
    for (i = 0; i &lt;friends; i++)
    {
        free(*(friendBook+i));   
    }
    free(friendBook);
    system("PAUSE");
    return 0;
}  
</code></pre>
