Hi,
I am having a problem with using sscanf on the following string:
$one,184943.000,3409.0533,N,11817.0188,W
this is my sscanf function:
sscanf(line,"%4c,%lf,%f,N,%f,W",t1,&t2,&t3,&t4);
What am I doing wrong?
Hi,
I am having a problem with using sscanf on the following string:
$one,184943.000,3409.0533,N,11817.0188,W
this is my sscanf function:
sscanf(line,"%4c,%lf,%f,N,%f,W",t1,&t2,&t3,&t4);
What am I doing wrong?
%c is for 1 character
to read string upto 4 characters
%4s
to read string stopping on , upto 4 characters
%4[^,]
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Thanks for your reply, I realised that I was not specific about the problem that I am having.
I can read the start string (one) but I am not able to read 3409.0533 instead of that it gives me the third value 11817.0188 and in the third float, it gives me the third value again.
I cannot figure out why.
Have no problem with thisCode:#include <stdio.h> int main() { const char* line = "$one,184943.000,3409.0533,N,11817.0188,W"; char t1[5] = ""; double t2 = 0.0; float t3 = 0.0f, t4 =0.0f; int ret = sscanf(line,"%4[^,],%lf,%f,N,%f,W",t1,&t2,&t3,&t4); return 0; }
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Strange thanks, ill look into it