Split String in C to recognize consecutive tabs
问题 I have a file that has certain fields separated by tabs. There will always be 17 tabs but there order can vary, such as.. 75104\tDallas\t85\t34.46\t45.64 75205\tHouston\t\t37.34\t87.32 93434\t\t\t1.23\t3.32 When I use strtok in the following fashion while (fgets(buf, sizeof(buf), fp) != NULL) { tok = strtok(buf,"\t"); while(tok != NULL) { printf("%s->",tok); tok = strtok(NULL,"\t"); } } I get all the tokens, but double tabs \t\t or more are ignored. However, I need to know when a field is