Hi
I am having a file called Log.csv which contains 196 columns 9 of them empty and 1447 rows, I start reading the file but as I think I am facing a problem of getting the whole data, actually it gives me empty screen when print out on the screen.
I need some help in reading the csv file and put it in array because later on I have to get the date (from the first column) and min,max for some other columns.
I am really gratefull if anyone can help me.
I am going to paste 1 line from my Log.csv and then paste my code.
11/10/2004,00:00:45,190,0,13.94,346.81,201.11,18.46,32,3,47,6, ,127,230,228,228,348,128,64,64,8,6,6,50,50,50,34,34,35,6,6,6,0, ,63,230,228,230,344,66,66,66,8,6,7,50,50,50,35,36,35,6,6,6,0, ,49.41,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,0.06,30.91,00,63,6,4,0, ,49.67,0.00,0.06,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,32.87,00,63,6,4,0, ,49.67,0.00,-0.30,32.87,00,63,6,4,0, ,49.94,0.00,-0.30,30.91,00,63,6,4,0, ,49.41,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,30.91,00,63,6,4,0, ,49.41,0.00,-0.30,32.87,00,63,6,4,0, ,49.67,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,32.87,00,63,6,4,0, ,49.41,0.00,0.06,32.87,00,63,6,4,0, ,49.67,0.00,0.06,30.91,00,63,6,4,0, ,
My code is
#include <iostream>
#include <fstream>
using namespace std;
float matrix_points[1447][196];
int main()
{
std::ifstream input_file("Log.csv");
int row(0), col(0);
char buffer[256];
char line[255];
input_file.clear();
input_file.seekg(0);
/* brings all the data in .csv file and put them in an array*/
while(!(input_file.eof()))
{
for ( col=0; col<196; col++)
{
if (matrix_points[row][col] != matrix_points[row][195])
{
input_file.getline(line, sizeof(buffer), ',');
matrix_points[row][col] = atof(line);
}
else
{
input_file.getline(line, sizeof(buffer), '\n');
matrix_points[row][12] = atof(line);
}
}
row++;
}
/* for loop to print data on screen*/
for (int i=0; i< row ; i++)
for (int j=0; j< col ; j++)
{
if (matrix_points[i][j] != matrix_points[i][195])
cout << matrix_points[i][j] << " " ;
else
cout << matrix_points[i][195]<< endl;
}
cout << row <<endl;
cout << "\n\n";
// system("PAUSE");
return 0;
}