My program reads data from a .csv file it works fine when the data is in the correct format, but I wonder if it is possible to:
Check whether the loaded data only number (assumption of the program, the data can not be letters of the alphabet)
Check whether or not we load empty lines
Is the number of loaded characters, eg 8.
If so, how can I do it?
int main(){
ifstream ip('table.csv');
if(!ip.is_open()){
cout << "ERROR" << endl;
}
int n = 3926;
const int CAPACITY = 3926;
const int CAPACITY2 = 7;
string multi [CAPACITY][CAPACITY2];
float TABLE[CAPACITY][CAPACITY2];
if(ip.good()){
for ( int i=0; i<=3925; i++)
{
int k=0;
getline(ip, multi[i][k], ',');
getline(ip, multi[i][k+1], ',');
getline(ip, multi[i][k+2], ',');
getline(ip, multi[i][k+3], ',');
getline(ip, multi[i][k+4], ',');
getline(ip, multi[i][k+5], ',');
getline(ip, multi[i][k+6], '\n');
// change from char to float
TABLE[i][k] = atof(multi[i][k].c_str());
TABLE[i][k+1] = atof(multi[i][k+1].c_str());
TABLE[i][k+2] = atof(multi[i][k+2].c_str());
TABLE[i][k+3] = atof(multi[i][k+3].c_str());
TABLE[i][k+4] = atof(multi[i][k+4].c_str());
TABLE[i][k+5] = atof(multi[i][k+5].c_str());
TABLE[i][k+6] = atof(multi[i][k+6].c_str());
}
}