Note that there are some explanatory texts on larger screens.

plurals
  1. POA bug of using for loop to print out matrix in my program
    primarykey
    data
    text
    <p>I wrote the following code to test in <code>int main()</code></p> <pre><code>int main() { int *p1 = findmatrixsize("inputmatrix.txt","A");//A function gets matrix size cout &lt;&lt; p1[0] &lt;&lt; endl &lt;&lt; p1[1] &lt;&lt; endl; int *p2 = findmatrixsize("inputmatrix.txt","B"); cout &lt;&lt; p2[0] &lt;&lt; endl &lt;&lt; p2[1] &lt;&lt; endl; double **C = normalmultiplication("inputmatrix.txt","A", "B"); cout &lt;&lt; C[0][0] &lt;&lt; endl; ofstream fout; const string s="outputmatrix.txt"; fout.open(s); for(int i=0;i&lt;p1[0];i++){ for(int j =0;j&lt;p2[1];j++){ fout &lt;&lt; C[i][j] &lt;&lt; " "; } fout&lt;&lt; endl; } fout.close(); return 0; } </code></pre> <p>Everything works except when I am executing the multiarray printing. Here is the problem:</p> <p>1.If I comment out the printing part, <code>p1[0],p1[1],p2[0],p2[1],C[i][j]</code> gives me perfect and correct result that I want.</p> <p>2.However, when I print by using normal loops it doesn't work. But, but,but, if I change the <code>p1[0],p2[1]</code> in the for loop to a concrete number like 3(when my matrix dimension is 3), it works again. </p> <p>3.It compiles, but the for loop printing part is not written into the txt. When I changed it to the standard print cout(not only the single line, I mean the whole method), I couldn't see them in the terminal neither. But as I mentioned above, when I change p[0] p[1] to 3, it works, which means I can see them either in the txt or terminal </p> <p>I have never met such weird situation in C++ before, so I hope someone can help me out!</p> <p>FYI, I use Visual Studio 2010 as compiler.</p> <p>Thanks for your help!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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