fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main() {
  5. char c, *ptr, str[256], n[16];
  6. int i = 0, j = 0, len;
  7. long sum = 0;
  8.  
  9. while ((c = getchar()) != EOF) {
  10. str[i] = c;
  11. i++;
  12. }
  13. str[i] = '\0';
  14. len = strlen(str);
  15. for (i = 0; i <= len; i++) {
  16. n[j] = str[i];
  17. j++;
  18. if ((str[i] == 32) || (str[i] == '\n')) {
  19. n[j] = '\0';
  20. if ((n[0] == '\0') || (n[0] < 48) || (n[0] > 57)) {
  21. char n[2] = {'0', '\0'};
  22. }
  23. sum = sum + strtol(n, &ptr, 10);
  24. j = 0;
  25. }
  26. }
  27. printf("\n%ld\n", sum);
  28. }
Success #stdin #stdout 0s 4716KB
stdin
100 + 23 = 123
$100 - 23 = 77.
stdout
269