Advertisement
Josif_tepe

Untitled

Feb 14th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #define MAX 505
  5. int main(int argc, char* argv[])
  6. {
  7.     FILE *input = fopen(argv[1], "r");
  8.     FILE *output = fopen(argv[2], "w");
  9.     if(input == NULL) {
  10.         printf("Ne e dobro!");
  11.         return 0;
  12.     }
  13.     char niza[MAX];
  14.     while(fgets(niza, 100, input)) {
  15.         int brojac[26];
  16.         for(int i = 0; i < 26; i++) {
  17.             brojac[i] = 0;
  18.         }
  19.         for(int i = 0; i < strlen(niza); i++) {
  20.             niza[i] = tolower(niza[i]);
  21.         }
  22.         for(int i = 0; i < strlen(niza); i++) {
  23.             brojac[niza[i] - 'a']++;
  24.         }
  25.         for(int i = 0; i < 26; i++) {
  26.             if(brojac[i] > 0) {
  27.                 fprintf(output, "%c %d\n", (char)(i + 'a'), brojac[i]);
  28.             }
  29.         }
  30.         fprintf(output, "\n");
  31.     }
  32.     return 0;
  33. }
  34. /*
  35.  5 4
  36.  1 2 7 3
  37.  2 2 4 0
  38.  5 6 0 1
  39.  1 2 3 4
  40.  3 2 0 12
  41.  3 4
  42.  1 2 3 0
  43.  5 6 0 7
  44.  -1 -2 -3 12
  45.  */
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement