0

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:

  1. Check whether the loaded data only number (assumption of the program, the data can not be letters of the alphabet)

  2. Check whether or not we load empty lines

  3. 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());
        }
    }
Jack G.
  • 21
  • 4
  • Folks, if you're to down vote someone's question, at least have the courtesy to leave a constructive comment. Drive-by down-voting is so childish. – Andy Evans May 17 '17 at 19:27
  • I tried to find a solution, but I do not deal with programming on a daily basis, so I asked a question and I count on any help. :) – Jack G. May 17 '17 at 19:31
  • Take a look at [Read file line by line](http://stackoverflow.com/questions/7868936/read-file-line-by-line) answer 1, option 2 for a better ideology for reading the file that will resolve point 2 and quite a few other failure cases you don't seem to be aware of. – user4581301 May 17 '17 at 21:05

0 Answers0