fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. int cnt = 0;
  6. char *str = "2.55 54.11 -1.00000 2.222";
  7. char *ptr = str, *eptr;
  8. do {
  9. strtof(ptr, &eptr);
  10. ptr = eptr;
  11. cnt++;
  12. } while (*eptr);
  13. printf("%d\n", cnt);
  14. float *res = malloc(cnt*sizeof(float));
  15. ptr = str;
  16. for (int i = 0 ; i != cnt ; i++) {
  17. res[i] = strtof(ptr, &eptr);
  18. ptr = eptr;
  19. }
  20. for (int i = 0 ; i != cnt ; i++) {
  21. printf("%f\n", res[i]);
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 2380KB
stdin
Standard input is empty
stdout
4
2.550000
54.110001
-1.000000
2.222000