Dear All,
I have basic structure of the C++ code [1]. It suppose to read particular columns from some txt file. The txt file look like following [1] (snippet). I have to ask the details for instance 'id' information for rows satisfying text with red color. The issue is that the txt file has not just the column wise data but other stuff as well, as you can check the [2]. Besides, the most important is I need to select data only for columns with phase has certain value.
Thanks in advance,
emily,
ISSUEs facing:
a.) if there are top line with the
number side id id_2 phase particulers cost phase
, it is acepting. Else if more than one such line is there, its not working.
b.) When I perform test with small file of some 500 lines, and tried to cout. It fail with
Segmentation fault (core dumped)
c.) The TASK is to plot
id vs id_2
for certain condition being true, please check the BLUE text in the code
[1]
-----------------------------------------------------
#include <iostream>
#include <stdlib.h>
#include <string>
usign namespace std;
int main(int argc, char *argv[]){
int number[2600], side[2600] , id[2600] , id_2[2600] , phase[2600] ,cost[2600], phase[2600],
string particulers[2600];
string fileToOpen = argv[1];
if(argc!= 1 || argc < 2) {
cout<<"Error :check the no of input, require input.txt "<<endl;
exit(0);
}
//open the file
ifstream inFile(fileToOpen.c_str());
if(!inFile.is_open())
{
cout << "Problem opening the file. Program terminating." << endl;
exit(EXIT_FAILURE);
}
while(!inFile.eof()){
inFile.ignore(numeric_limits<streamsize>::max(), '\n');
inFile >> number >> side >> id >> id_2 >> phase >> particulers >> cost >> phase ;
if (particulers.compare("top") == 0 && phase == 0 ){
// PLOT (id vs id_2)
}
i++;
}
i--;
}
}
[2]
--------------------------------------------------
number side id id_2 phase particulers cost phase
-1 20 98 9 87 HO001 725 0
-1 50 98 10 87 HO002 725 0
-1 30 97 9 90 HO003 728 0
-1 30 97 9 90 HO003 728 0
-1 20 98 15 87 HO001 725 1
-1 50 98 16 87 HO002 725 0
-1 30 97 19 90 HO003 728 1
-1 30 97 20 90 HO003 728 1
number side id id_2 phase particulers cost phase
-1 20 98 45 87 HO001 730 1
-1 50 98 80 87 HO002 745 1
-1 30 97 90 90 HO003 759 1
-1 30 97 50 90 HO003 739 1