Need to know when no data appears between two token separators using strtok()
I am trying to tokenize a string but I need to know exactly when no data is seen between two tokens. e.g when tokenizing the following string " a,b,c,,,d,e " I need to know about the two empty slots between ' d ' and ' e '... which I am unable to find out simply using strtok() . My attempt is shown below: char arr_fields[num_of_fields]; char delim[]=",\n"; char *tok; tok=strtok(line,delim);//line contains the data for(i=0;i<num_of_fields;i++,tok=strtok(NULL,delim)) { if(tok) sprintf(arr_fields[i], "%s", tok); else sprintf(arr_fields[i], "%s", "-"); } Executing the above code with the