Advertisement
sellmmaahh

Datoteke-JednakeCifre

Aug 9th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int JednakeCifre (int *niz, int vel) {
  5.     int br=0,i=0,cifra,temp;
  6.     int iste=1;
  7.     for (i=0; i<vel; i++) {
  8.           temp=*(niz+i);
  9.             cifra=temp%10;
  10.          temp/=10;
  11.           while (temp!=0) {
  12.                 if (temp%10!=cifra)
  13.                    {  iste=0;
  14.                       break;
  15.                    }
  16.                    if (iste=0) break;
  17.                 temp/=10;
  18.           }
  19.           iste=1;
  20.           if (iste==1) br++;
  21.     }
  22.     return br;
  23. }
  24. int main () {
  25.     FILE *ulaz=fopen("mjerenja.txt","r");
  26.     if (ulaz==NULL) {
  27.         printf("Greska pirlikom otvaranja ulazne datoteke.");
  28.         exit(1);
  29.     }
  30.     FILE *izlaz=fopen("statistika.txt","w");
  31.     if (izlaz==NULL) {
  32.         printf("Greska prilikom otvaranja izlazne datoteke.");
  33.         fclose(ulaz);
  34.         exit(1);
  35.     }
  36.     int niz[100];
  37.     int i=0;
  38.     char c;
  39.     do {
  40.         fscanf(ulaz,"%d",&niz[i+1]);
  41.     } while((c=fgetc(ulaz))!=EOF && i<100);
  42.     fclose(ulaz);
  43.    
  44.     int rez=JednakeCifre(niz,100);
  45.     fprintf("izlaz","%d",rez);
  46.     fclose(izlaz);
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement