Advertisement
legasov

Untitled

Jan 18th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #define MAX 100
  5.  
  6. //ne menuvaj!
  7. void wtf() {
  8.     FILE *f = fopen("input.txt", "w");
  9.     char c;
  10.     while((c = getchar()) != EOF) {
  11.         fputc(c, f);
  12.     }
  13.     fclose(f);
  14. }
  15.  
  16. void sortiraj(char *niza, int n) {
  17.     int i, j;
  18.     for(i = 0; i < n - 1; i++) {
  19.         for(j = 0; j < n - 1 - i; j++) {
  20.             if (niza[j] > niza[j+1]) {
  21.                 int temp = niza[j];
  22.                 niza[j] = niza[j+1];
  23.                 niza[j+1] = temp;
  24.             }
  25.         }
  26.     }
  27.  
  28. }
  29.  
  30. int main() {
  31.     wtf();
  32.  
  33.     // vashiot kod ovde
  34.  
  35.     FILE *f;
  36.  
  37.     if ( (f = fopen("datoteka.txt","r")) == NULL) {
  38.         printf("Unable to open");
  39.         return -1;
  40.     }
  41.  
  42.     int cifri = 0, i;
  43.     char niza[MAX], broevi[MAX];
  44.  
  45.     while((fgets(niza, MAX, f)) != NULL) {
  46.         for(i=0; i<strlen(niza); i++) {
  47.             if(isdigit(niza[i])) {
  48.                 cifri++;
  49.                 broevi[i] = niza[i];
  50.             }
  51.         }
  52.  
  53.         sortiraj(broevi, i);
  54.         printf("%d:",cifri);
  55.         for(int i = 0; i < cifri - 1; i++)
  56.             printf("%d", broevi[i]);
  57.  
  58.         printf("\n");
  59.  
  60.     }
  61.     fclose(f);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement