The following function works on text file called "_filePath" and tries to cut it to little tokens separate by ";" and "," like this:
[Mickey M;12034;911416313;M;01a;9001;NULL;0;13;12;0;CPP,C;MSC,3D;FEND,BEND,SEC;]
When trying to separate CPP,C
into little token, it doesn't reach the next token which is MSC,3D
and so on.
I notice that the function doesn't even reach the block beginning with if (tokNum==1)
.
I really need HELP, thank you very much :D
void File::set() {
if (_filePath.is_open()) {
while (_filePath.getline(line, 250)) {
char *token; char *tokeng;
int tokNum = 0;
token = strtok(line, ";");
while (token != NULL) {
index = 0;
if (token == "NULL") token = NULL;
if (inputType == EMP){
if (tokNum == 0){
int numWord = seprateElements(token);
empKnoledge = new string[numWord];
tokeng = strtok(token, ",");
while(tokeng != NULL) {
empKnoledge[index] = tokeng;
index++;
tokeng = strtok(NULL, ",");
}
}
if (tokNum == 1){
int numWord = seprateElements(token);
empAfeild = new string[numWord];
tokeng = strtok(token, ",");
while(tokeng != NULL) {
empAfeild[index] = tokeng;
index++;
tokeng = strtok(NULL, ",");
}
}
if (tokNum == 2){
int numWord = seprateElements(token);
empPfeild = new string[numWord];
tokeng = strtok(token, ",");
while (tokeng != NULL) {
empPfeild[index] = tokeng;
index++;
tokeng = strtok(NULL, ",");
}
}
}
tokNum++;
token = strtok(NULL, ";");
}
numLine++;
}
}
getchar();
}
int seprateElements(char *line) { // check size of elements in line by counting ','
int count = 0;
while (*line++ != '\0') {
if (*line == ',') count++;
}
return count+1;
}