Eg: input: char *str1 = "the are all is well"; char *str2 = "is who the"; output: common words in two given strings, return 2D array of strings.
#define SIZE 31
char ** commonWords(char *str1, char *str2) {
    int i,j=0,count1,count2,k=0,a,b,m=0,n;
    char str3[100][100], str4[100][100];
    char **output;
    output = (char **)malloc(SIZE*sizeof(char*));
    if (str1 == NULL || str2 == NULL)
    {
        return NULL;
    }
    for (i = 0; str1[i] != '\0'; i++)
    {
        if (str1[i] != ' ')
        {
            str3[j][k++] = str1[i];
        }
        else
        {
            str3[j][k++] = '\0';
            j++;
            k = 0;
        }
    }
    str3[j][k++] = '\0';
    count1 = j > 0 ? j + 1 : j;
    j =  k = 0;
    for (i = 0; str2[i] != '\0'; i++)
    {
        if (str2[i] != ' ')
        {
            str4[j][k++] = str2[i];
        }
        else
        {
            str4[j][k++] = '\0';
            j++;
            k = 0;
        }
    }
    str4[j][k++] = '\0';
    count2 = j > 0 ? j + 1 : j;
    for (i = 0; i < count1; i++)
    {
        for (j = 0; j < count2; j++)
        {
            if (str3[i][k] == str4[j][k])
            {
                if (str3[i][k + 1] == str4[j][k + 1] && str3[i][k + 2] == str4[j][k + 2] == '\0')
                {
                    a = i;
                    b = k;
                    while (str3[a][b] != '\0')
                    {
                        output = (char **)malloc(SIZE*sizeof(char));
                        output[m][n] = str3[a][b];
                        n++;
                        b++;
                    }
                    output[m][n] = '\0';
                }
                else if (str3[i][k + 1] == str4[j][k + 1] && str3[i][k + 2] == str4[j][k + 2])
                {
                    a = i;
                    b = k;
                    while (str3[a][b] != '\0')
                    {
                        output = (char **)malloc(SIZE*sizeof(char));
                        output[m][n] = str3[a][b];
                        n++;
                        b++;
                    }
                    output[m][n] = '\0';
                    m++;
                }
            }
        }
    }
    return output;
    }
I am debugging this code in visual studios and the test is failed.Its showing this " message: Exception code: C0000005" .It means error related to memory space allocation.So where did i go wrong?
 
     
    