#160521 - ragefury32 - Thu Jul 17, 2008 5:59 am
Hm. So I ran into a weird problem with sccanf() -
So I have a block of code that look something like this:
(Basically it goes to a non-blocking socket and pulls a string out of a server once every 5 seconds, a string that looks like:
recreation area|3.12332324|1.3234424|0|0
For some reason, the sscanf() always fail on the %f. What seems to be the problem? Is there something in terms of the sccanf that makes it bad?
So I have a block of code that look something like this:
Code: |
while((recv(my_socket, p, 1, 0) != 0) || i < 2000) { if (*p == '\n') { *p = '\0'; char *area = linebuf; char *rest = strchr(linebuf, '|'); *rest = '\0'; p = linebuf; i = 0; char * cptr = NULL; char pipe[] = "|"; printf("%s\n", rest+1); cptr = strtok(rest+1, pipe); sscanf(cptr, "%4d", &tagid); iprintf("%4d, %f, %f, %f, %d\n", tagid, tx, ty, tz, flags); cptr = strtok( NULL, pipe); sscanf(cptr, "%f", &tx); iprintf("%4d, %f, %f, %f, %d\n", tagid, tx, ty, tz, flags); cptr = strtok( NULL, pipe); sscanf(cptr, "%f", &tz); iprintf("%4d, %f, %f, %f, %d\n", tagid, tx, ty, tz, flags); cptr = strtok( NULL, pipe); sscanf(cptr, "%f", &ty); iprintf("%4d, %f, %f, %f, %d\n", tagid, tx, ty, tz, flags); cptr = strtok( NULL, pipe); sscanf(cptr, "%d\n", &flags); iprintf("%4d, %f, %f, %f, %d\n", tagid, tx, ty, tz, flags); break; } |
(Basically it goes to a non-blocking socket and pulls a string out of a server once every 5 seconds, a string that looks like:
recreation area|3.12332324|1.3234424|0|0
For some reason, the sscanf() always fail on the %f. What seems to be the problem? Is there something in terms of the sccanf that makes it bad?