Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ran the following code without incident for values of <code>n</code> that included 1000 and 2000:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(int argc, const char *argv[]) { int n, i; printf("Enter n: "); scanf("%d", &amp;n); double **a, **b, **result; /* Init matrices*/ a = malloc(n * sizeof(double*)); b = malloc(n * sizeof(double*)); result = malloc(n * sizeof(double*)); if (a == NULL || b == NULL || result == NULL) { printf("Error.\n"); return 1; } for (i = 0; i &lt; n; i++) { *(a + i) = malloc(n* sizeof(double)); *(b + i) = malloc(n* sizeof(double)); *(result + i) = calloc(n, sizeof(double)); } for (i = 0; i &lt; n; i++) { free(a[i]); free(b[i]); free(result[i]); } free(a); free(b); free(result); return 0; } </code></pre> <p>Perhaps there is something going on with the functions which manipulate <code>a</code>, <code>b</code> and <code>result</code>. For one, if you are multiplying two two-dimensional arrays and putting the end result into a variable called <code>result</code>, your multiplication function should probably be taking a triple pointer to <code>result</code>, e.g.:</p> <pre><code>/* allocate space for a, b and result... */ foo(a, b, &amp;result); /* do something with result... */ </code></pre> <p>You might double-check your function signatures and code.</p> <p>If you are using <code>gcc</code>, compile your code with the <code>-Wall</code> warning set:</p> <pre><code>$ gcc -Wall foo.c -o foo.bin </code></pre> <p>Also perhaps consider using the <code>gdb</code> debugger to find out where the crash is occurring exactly and what values your data are holding at that time. I'm not an expert in it and I find <a href="http://www.unknownroad.com/rtfm/gdbtut/" rel="nofollow">RMS's tutorial</a> to be a useful resource to come back to.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload