fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. double text2double(const char *p) {
  6. char *v = strchr(p, ',');
  7. if (v) *v = '.';
  8. return strtod(p, NULL);
  9. }
  10.  
  11. int main(void) {
  12. double x, y = 0;
  13. char buf[100];
  14. while (fgets(buf, sizeof buf, stdin)) {
  15. x = text2double(buf);
  16. printf("%f\n", x);
  17. y += x;
  18. }
  19. printf("total: %f\n", y);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 9424KB
stdin
42,42
42.42
0.666
0,555
,444
.333
stdout
42.420000
42.420000
0.666000
0.555000
0.444000
0.333000
total: 86.838000