fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_ARRAY_SIZE 25
  5.  
  6. int main (void) {
  7.  
  8. double ary[MAX_ARRAY_SIZE]; // MAX_ARRAY_SIZE being some defined value
  9. char buffer [512];
  10. char* ptr = buffer;
  11. int i = 0, j;
  12.  
  13. printf ("Enter your values separated by spaces: ");
  14. fgets (buffer, sizeof (buffer), stdin);
  15.  
  16. while (i < MAX_ARRAY_SIZE && ptr) {
  17. sscanf (ptr, "%lf", &ary[i]);
  18. ptr++;
  19. i++;
  20. ptr = strchr(ptr, '\040');
  21. }
  22.  
  23. putchar ('\n');
  24.  
  25. for (j = 0; j < i; j++)
  26. printf ("%.2f\n", ary[j]);
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 2252KB
stdin
2 32 12.2 4 5 66.3 60 286 33.53 56
stdout
Enter your values separated by spaces: 
2.00
32.00
12.20
4.00
5.00
66.30
60.00
286.00
33.53
56.00