I have a CSV file with dates (that I converted from excel) but I'm having trouble parsing them using the strtok function. When I delete the column with dates from the CSV file it works fine, but I get an error otherwise. I've been playing around with it for hours but the error(s) won't go away. I'd greatly appreciate any help/advice! I'm a programming beginner. Here is what I have (bolded part is the part I took out for the program to work, without dates in the CSV file):
void parseFile (ifstream &myfile) {
string line;
int n = 1;
while ( myfile.good() ) {
//storing each line into char array
getline(myfile,line);
char data[100];
for (int g = 0; g <= line.size(); g++) {
data[g] = line[g];
}
//using strtok to read char array
char * tok;
tok = strtok (data,",");
while (tok != NULL) {
temp.patientID = atol(tok);
tok = strtok(NULL, ",");
temp.result = atof(tok);
tok = strtok(NULL, ",");
tok = strtok(NULL, "/");
tok = strtok(NULL, "/");
temp.date = atof(tok);
tok = strtok(NULL, " ");
tok = strtok(NULL, ":");
tok = strtok(NULL, ":");
temp.time = atof(tok);
tok = strtok(NULL, ",");
//getting each component and storing into map that stores parsed info, mymap
mymap.insert (pair<int,testInfo>(n,temp));
n++;
}
}
}
My CSV
file looks something like this:
1000856,0,28/09/2014 02:34:37
1002259,0.008,15/09/2014 23:14:11
1002259,0.002,18/09/2014 10:44:18
1002259,0.005,18/09/2014 16:54:52
1003348,0.038,20/03/2015 12:50:46