I have a string "1|4|1577|1|10.22.33|7001390280000019|||||172.20.5.20|1" and I want to split this string to get a result like this:
1
4
1577
10.22.33
7001390280000019
null
null
null
null
172.20.5.20
1
But when I use strtok in a while cycle, the pipes that doesn't have any content are not showing, so my result looks like this:
1
4
1577
1
10.22.33
7001390280000019
172.20.5.20
1
How can I get this result?
Here is my code:
int main(argc,argv)
int argc;
char *argv[];
{
char *var1="1|4|1577|1|10.22.33|7001390280000019|||||172.20.5.20|1";
char *var2=malloc(strlen(var1)+1);
strcpy(var2,var1);
while ((var2 = strtok(var2, "|")) != NULL){
printf("<<%s>>\n", var2);
var2= NULL;
}
return 0;
}
Thanks in advance