I have a text file like this;
1 13 330 323 18 1 40 410 413 45 1 28 381 347 16 1 16 230 261 27
2 6 208 218 8 2 24 253 277 21 2 13 223 244 14 2 10 177 185 6
3 0 12 1 1 3 20 417 416 18 3 23 322 320 23 3 5 21 23 4
4 1 7 18 2 4 11 149 138 11 4 11 120 116 10 4 2 27 24 3
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.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <string.h>
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 < 20; x++)
{
for ( y = 0; y < 40; y++)
{
a[x][y] = 0;
}
}
for (x = 0; x < 20; x++)
{
for ( y = 0; y < 40; y++)
{
fscanf(myDataFile1, "%d,", &a[x][y] );
}
}
for (x = 0; x < 20; x++)
{
for ( y = 0; y < 40; y++)
{
sum = a[x][y];
}
}
int maxValue = 0;
for(x = 1; x < 20; x++)
{
for(y = 1; y < 40; y++)
{
if(a[x][y] > maxValue)
{
maxValue = a[x][y];
}
}
}
if (myOutFile1.is_open())
{
myOutFile1 << left << setw (5) << maxValue << endl;
}
cout << "The highest value is: " << maxValue << endl;
}
}