D
dkk
Here is the code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float f;
int part1, part4;
float part2;
char part3[6];
char s[]="1234.56abc 903";
char *p;
sscanf(s, "%2d%5e%5s%d", &part1, &part2, &part3, &part4);
printf("parse string: %s\n", s);
printf("part1=%d\n", part1);
printf("part2=%f\n", part2);
printf("part3=%s\n", part3);
printf("part4=%d\n", part4);
return 0;
}
Here is the result:
parse string: 1234.56abc 903
part1=12
part2=34.560001
part3=abc
part4=903
question is why part2 is 34.560001, I expect this number to be 34.56.
Is there a way I can get exact 34.56?
Thanks.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float f;
int part1, part4;
float part2;
char part3[6];
char s[]="1234.56abc 903";
char *p;
sscanf(s, "%2d%5e%5s%d", &part1, &part2, &part3, &part4);
printf("parse string: %s\n", s);
printf("part1=%d\n", part1);
printf("part2=%f\n", part2);
printf("part3=%s\n", part3);
printf("part4=%d\n", part4);
return 0;
}
Here is the result:
parse string: 1234.56abc 903
part1=12
part2=34.560001
part3=abc
part4=903
question is why part2 is 34.560001, I expect this number to be 34.56.
Is there a way I can get exact 34.56?
Thanks.