Guest User

Untitled

a guest
Oct 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define CHARS 26
  4. #define LEN 1000
  5.  
  6. void strLowerCase(char str[]) {
  7.     for ( ; *str; str++ ) {
  8.         if ( *str >= 'A' && *str <= 'Z' ) {
  9.             *str += 32;
  10.         }
  11.     }
  12. }
  13.  
  14. int main() {
  15.     FILE *in = fopen("task.in", "r");
  16.     FILE *out = fopen("task.out", "w");
  17.     char str[LEN];
  18.     int counters[CHARS];
  19.     int len = 0;
  20.    
  21.     for ( int i = 0; i < CHARS; i++ ) {
  22.         counters[i] = 0;
  23.     }
  24.    
  25.     for ( int i = 0; fscanf(in, "%c", &str[i]) == 1; i++ ) {
  26.         if ( str[i] != '\n' ) {
  27.             len += 1;
  28.         }
  29.     }
  30.    
  31.     strLowerCase(str);
  32.    
  33.     for ( int i = 0; i < len && str[i] != EOF; i++ ) {
  34.         int temp = str[i];
  35.        
  36.         temp = str[i] - 97;
  37.         counters[temp] += 1;
  38.     }
  39.    
  40.     for ( int i = 0, j = 97; i < CHARS; i++, j++ ) {
  41.         if ( counters[i] > 0 ) {
  42.             fprintf(out, "%c %d\n", j, counters[i]);
  43.         }
  44.     }
  45.    
  46.     fclose(in);
  47.     fclose(out);
  48.    
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment