how to get max values from each string in a text file - C++
<p>I have a text file like this;</p>

<p>1    13   330  323  18   1    40   410  413  45   1    28   381  347  16   1    16   230  261  27<br>
2    6    208  218  8    2    24   253  277  21   2    13   223  244  14   2    10   177  185  6<br>
3    0    12   1    1    3    20   417  416  18   3    23   322  320  23   3    5    21   23   4<br>
4    1    7    18   2    4    11   149  138  11   4    11   120  116  10   4    2    27   24   3 </p>

<p>and i want to take each string's maximum value. For example, in 1st string, i have 413 for highest number, for the 2nd i have 277. And i have 40 lines like this. I used this code but my code doesn't working properly - i knew i do it wrong btw- it takes all of the arrays and takes just only 1 highest value. I think i need two for loops for doing this but i already done first wrong and there in no 2nd one :) Maybe this can be done with "getline" function i really don't know but i need your help atm... Thanks.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iomanip&gt;
#include &lt;fstream&gt;
#include &lt;string.h&gt;

using std::cin;
using std::endl;
using std::cout;
using namespace std;

int main()
{
    int a[20][40]; 
    int x,y;  
    int sum = 0;
    FILE *myDataFile1;  
    ofstream myOutFile1;
    myOutFile1.open ("highestValues.txt"); 

    myDataFile1 = fopen("input.txt", "r");

    for ( x = 0; x &lt; 20; x++)
    {
        for ( y = 0; y &lt; 40; y++)
        {
            a[x][y] = 0;
        }
    }


    for (x = 0; x &lt; 20; x++)
    {
        for ( y = 0; y &lt; 40; y++)
        {
            fscanf(myDataFile1, "%d,", &amp;a[x][y] );
        }
    }

    for (x = 0; x &lt; 20; x++)
    {
        for ( y = 0; y &lt; 40; y++)
        {
            sum = a[x][y];
        }
    }

    int maxValue = 0;


    for(x = 1; x &lt; 20; x++)
    {
        for(y = 1; y &lt; 40; y++)
        {
            if(a[x][y] &gt; maxValue)
            {
                maxValue = a[x][y];
            }
        }
    }

    if (myOutFile1.is_open())
    {
        myOutFile1 &lt;&lt; left &lt;&lt; setw (5) &lt;&lt; maxValue &lt;&lt; endl;
    }
    cout &lt;&lt; "The highest value is: " &lt;&lt; maxValue &lt;&lt; endl;
}
</code></pre>

<p>}</p>