Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. void Vrati(char * ulaz, int velicina)
  7. {
  8.     char za_vratiti[256];
  9.     int niz[26];
  10.     int i, mjesto_u_nizu;
  11.     int isprintano = 0;
  12.     for (i = 0; i < 26; i++)
  13.         niz[i] = 0;
  14.  
  15.     for (i = 0; i < velicina; i++)
  16.     {
  17.         if ((ulaz[i] >= 'a' && ulaz[i] <= 'z') || (ulaz[i] >= 'A' && ulaz[i] <= 'Z'))
  18.         {
  19.             if (ulaz[i] >= 'A' && ulaz[i] <= 'Z')
  20.                 mjesto_u_nizu = ulaz[i] - 'A';
  21.             else
  22.                 mjesto_u_nizu = ulaz[i] - 'a';
  23.  
  24.             niz[mjesto_u_nizu]++;
  25.         }
  26.     }
  27.  
  28.     for (i = 0; i < 26; i++)
  29.     {
  30.         if (niz[i] > 0)
  31.             isprintano += sprintf(za_vratiti + isprintano, "%c%d", 'a' + i, niz[i]);
  32.     }
  33.  
  34.     strncpy(ulaz, za_vratiti, velicina);
  35.  
  36. }
  37.  
  38. int main()
  39. {
  40.     char ulaz[10] = "aabbbcccd";
  41.     Vrati(ulaz, 10);
  42.     printf("%s\n", ulaz);
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement