Segmentation Fault (Core Dump) with 2D Dynamic Array : <p>I'm writing a program that takes a number(s) from the command line and finds all the prime factors of said number. I want to collect the prime factors of each number inside an array of pointers, so that each pointer will point to each specific group of prime factors for each number entered. I'm currently running into a segmentation fault core dump and from what I've been able to research so far, I'm apparently trying to access a spot of either unallocated memory or something to do with a NULL pointer. I've indicated in the code below where I found the segmentation fault taking place. I'm currently at a loss on how to proceed but I'm going to keep looking but in the meantime, if someone with a little better understanding of C wouldn't mind helping me out, that would be greatly appreciated. Eventually I have to take this code and get it to work with pthreads.</p>

<pre><code>`#include&lt;stdlib.h&gt;
 #include&lt;stdio.h&gt;
 #include&lt;string.h&gt;
 #include&lt;pthread.h&gt;`

 int main(int argc, char** argv){
    int **primeFactor = malloc((argc-1)*sizeof(int*));
    int i, j, counter, num, prime = 2;
    for(i = 1; i &lt; argc; i++){
            counter = 0;
            num = atoi(argv[i]);
            printf("The number is: %d", num);
            primeFactor[i-1] = malloc((atoi(argv[i])/2)*sizeof(int));
            while(num &gt; 1){
                    while(num % prime == 0){
                            num /= prime;
                            // Segmentation Fault
                      ==&gt;   *primeFactor[i] = prime;
                            printf("\n%d is a factor", prime);
                    }
                    prime++;
            }
            prime=2;
    }
    printf("\n");
    return 0;
}
</code></pre>
