newbie question about data I/O
Howdy, gurus
I want to write code to read in a large genomic file. The data look
like
Marker location freq T mu sigma_2 S p-
value
rs2977670 713754 0.925 779 9.604 141.278 2.202 0.02763
rs2977656 719811 0.992 793 9.120 134.796 2.733 0.00627
Here is my code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
vector<string> snp_list1,snp_list2,snp_list3;
vector<int> location1,location2,location3;
vector<double> freq1,freq2,freq3;
vector<int> T1,T2,T3;
vector<double> mu1,mu2,mu3;
vector<double> sigma_21,sigma_22,sigma_23;
vector<double> S1,S2,S3;
vector<double> p1,p2,p3;
//read in 1st data file;
FILE *in=fopen(argv[1],"r");
char line[128];
fgets(line,128,in); //skip the 1st row;
while (fgets(line,128,in))
{
cout << line << endl;
char *str = strtok(line, "\t"); // the space in "\t" is a tab
string marker(str);
snp_list1.push_back(marker);
str = strtok(NULL, "\t");
location1.push_back(atof(str));
str = strtok(NULL, "\t");
freq1.push_back(atof(str));
str = strtok(NULL, "\t");
T1.push_back(atof(str));
str = strtok(NULL, "\t");
mu1.push_back(atof(str));
str = strtok(NULL, "\t");
sigma_21.push_back(atof(str));
str = strtok(NULL, "\t");
S1.push_back(atof(str));
str = strtok(NULL, "\t");
p1.push_back(atof(str));
}
fclose(in);
//verify the vectors
for (int i=0; i<snp_list1.size();++i)
cout << snp_list1[i] << endl;
return 0;
}
I tried to run the code but always met errors shown as "error while
dumping state..(core dumped)". I am new to C++.Thanks a lot for your
input.