Hi All,
I wrote below code to readin line by line from stdin ex.
city=Boston;city=New York;city=Chicago\n
and then split each line by ';' delimiter and print each record. Then in yet another loop I try to split the record by '=' delimiter to get to the actual values. But for some reason then the main (first) loop doesn't loop beyond the first iteration, why?
char* del1 = ";";
char* del2 = "=";
char input[BUFLEN];
while(fgets(input, BUFLEN, fp)) {
input[strlen(input)-1]='\0';
char* record = strtok(input, &del1);
while(record) {
printf("Record: %s\n",record);
char* field = strtok(record, &del2);
while(field) {
printf("Field: %s\n",field);
field = strtok(NULL, &del2);
}
record = strtok(NULL, &del1);
}
}