Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <limits.h>
  6.  
  7. int main(void) {
  8. const size_t ARRAY_LEN = 256;
  9.  
  10. int data[ARRAY_LEN]; memset(data, 0, ARRAY_LEN*sizeof(int));
  11. int input = 0, max = INT_MIN, min = INT_MAX;
  12.  
  13. int ec = 0, separator = 0;
  14.  
  15. // Never read more data than you can store!
  16. for (size_t i = 0; i < ARRAY_LEN; ++i)
  17. {
  18. /* Load next input */
  19. ec = scanf("%i", &input);
  20. if (ec == EOF) break; // no more input
  21. if (ec != 1) { // conversion error
  22. fprintf(stderr, "Conversion error on input %zi!\n", i);
  23. return EXIT_FAILURE;
  24. }
  25.  
  26. data[i] = input;
  27.  
  28. /* Min/Max */
  29. if (input < min) min = input;
  30. if (input > max) max = input;
  31.  
  32. /* Check separator for EOL */
  33. separator = getchar();
  34. if (separator == EOF || ((char) separator) == '\n') break; // end of input
  35. if (!isspace(separator)) { // unsupported input
  36. fprintf(stderr, "Unsupported character after input %zi: %c\n", i, (char) separator);
  37. return EXIT_FAILURE;
  38. }
  39. }
  40.  
  41. printf("Minimum: %i\nMaximum: %i\n", min, max);
  42. return EXIT_SUCCESS;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement