The_Law

Untitled

Oct 9th, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #include <string.h>
  5.  
  6. enum
  7. {
  8.     MAX_DIGITS = 10
  9. };
  10.  
  11. void
  12. outpt(int* ans)
  13. {
  14.     for (int i = 0; i < MAX_DIGITS; ++i) {
  15.         printf("%d %d\n", i, ans[i]);
  16.     }
  17. }
  18.  
  19. int
  20. main(void)
  21. {
  22.     int cnt[MAX_DIGITS];
  23.     memset(cnt, 0, MAX_DIGITS * sizeof(int));
  24.  
  25.     char raw[PATH_MAX + 1];
  26.     if (fgets(raw, PATH_MAX, stdin) == NULL) {
  27.         outpt(cnt);
  28.     }
  29.  
  30.     int it = PATH_MAX;
  31.     while (raw[it] != '\n') {
  32.         --it;
  33.     }
  34.  
  35.     for (int i = 0; i < 3; ++i, --it) {
  36.         if (it >= 0 && (raw[it] == '\r' || raw[it] == '\n')) {
  37.             raw[it] = 0;
  38.         }
  39.     }
  40.  
  41.     FILE *inpt = fopen(raw, "r");
  42.     if (inpt == NULL) {
  43.         outpt(cnt);
  44.     }
  45.  
  46.     int curr;
  47.  
  48.     while((curr = getc_unlocked(inpt)) != EOF) {
  49.         if ('0' <= curr && curr <= '9') {
  50.             ++cnt[curr - '0'];
  51.         }
  52.     }
  53.  
  54.     outpt(cnt);
  55.  
  56.     free(inpt);
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment