Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #define ended(X) (X == '\n' || X == '\r' || X == '\0')
- #define SIZE 100
- int main (void)
- {
- double ans = 0, tmp;
- char line[SIZE];
- fgets(line, SIZE, stdin);
- char *endptr, *currptr = line;
- do
- {
- ans += tmp = strtod(currptr, &endptr);
- if (!tmp && currptr == endptr)
- return fputs("Invalid input", stderr);
- if (errno == ERANGE)
- return fputs("Out of range", stderr);
- currptr = endptr;
- }
- while (!ended(*endptr) && endptr - line + SIZE > 0);
- printf("= %g", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement