I'm trying to read a string using sscanf()
in a loop but the offset is zero. What is the correct way and is it possible at all to have track of the offset?
In the example here the offset
should be 5 but the actual value is 0 and I had to set it manually to 5.
char line[35]=" -123 1 -25-1245 -12";
char *data=line;
char buf[6];
int offset;
int n,i;
for(i=0;i<5;i++){
if(sscanf(data,"%5[^\n\t]s%n",buf,&offset)==1){
n=atoi(buf);
data+=5;//offset;
printf("n= %5d offset= %d\n",n, offset);
}
}
The result is:
n= -123 offset= 0
n= 1 offset= 0
n= -25 offset= 0
n= -1245 offset= 0
n= -12 offset= 0