-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadCSV.C
45 lines (39 loc) · 1.11 KB
/
ReadCSV.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
// File pointer
/* ifstream fin;
// Open an existing record
fin.open("HistParameters.csv");
if(fin.fail())
{cout<<"The file doesn't exist"<<endl;
}
int lines=0,Bins=0;
float xMin=999,xMax=999;
string variable;
std::cout<<"fileexists"<<std::endl;
// while (!fin.eof())
string line;
for(lines=0;lines<5;lines++)
{
lines++;
fin>>line;
std::cout<<line<<" \n";
//std::cout<<"Reading line "<<lines<<" ...."<<std::endl;
//fscanf(fin,"%s,%i,%f,%f \n",&variable, &Bins,&xMin,&xMax);
// fin>>variable>>",">>Bins>>",">>xMin>>",">>xMax>>"\n";
//getline ( fin, variable, ',' );
//getline ( fin, Bins, ',' );
//getline ( fin, xMin, ',' );
//getline ( fin, xMax, ',' );
std::cout<<lines<<", "<<variable<<", "<<Bins<<", "<<xMin<<", "<<xMax<<" \n"<<std::endl;
}
fin.close();
*/
FILE *HistPars = fopen("HistParameters.csv","r");
int lines=0,Bins=0; float xMin,xMax; char word[80];
while(!feof(fp))
{
fscanf(fp,"%i, %f ,%f ,%s \n",&Bins,&xMin,&xMax,word);
std::cout<<Bins<<", "<<xMin<<", "<<word<<" \n"<<std::endl;
}
fclose(fp);
}