Hi, how to parse a empty substring with sscanf.......
if my string str[]="is first,,third,final." i cannot able to read the third and final substring if my second substring is zero. Is there an solution to overcome this error.....?????
Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
char *tokenstring = "first,second,25.5,15";
int result, i;
double fp;
char o[10], f[10], s[10], t[10];
void main()
{
result = sscanf(tokenstring,"%[^','],%[^','],%[^','],%s", o,t,s,f);
fp = atof(s);
i = atoi(f);
printf("%s\n %lf\n %s\n %d\n", o,t,fp,i);
}
for this program if i execute my output is
>first
>second
>25.5
>15
but if i try to remove the substring "second" in the tokenstring pointer... and if i try to execute, then i get output as:
char *tokenstring = "first,,25.5,15";
>first
>(blank)
>0.00
>0
how do i read the third and fourth substring in the string"tokenstring"...any suggestions ??????????