Dimitrija

Laboratoriski 9 - 1 SP

Dec 27th, 2020 (edited)
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. void writeToFile() {
  6.     FILE *f = fopen("text.txt", "w");
  7.     char c;
  8.     while((c = getchar()) != '#') {
  9.         fputc(c, f);
  10.     }
  11.     fclose(f);
  12. }
  13.  
  14. int main() {
  15.     writeToFile();
  16.    
  17.     char c;
  18.     int s=0,l=0;
  19.     float v=0;
  20.  
  21.     //Go otvarame txt dokumentot
  22.     FILE *dat;
  23.     if((dat=fopen("text.txt","r"))==NULL){
  24.         fprintf(stderr,"ne se otvara za citanje");
  25.         return -1;
  26.     }
  27.  
  28.     //Go zemame sekoj element vo c i proveruvame ali e golem ili mal
  29.     while ((c=fgetc(dat))!=EOF){
  30.         if (isupper(c)){
  31.             s++;
  32.         }
  33.         else if (islower(c)){
  34.             l++;
  35.         }
  36.     }
  37.  
  38.     //frekvencija spored ravenkata dadena od samata zadacha
  39.     v=s+l;
  40.     printf("%.4f\n%.4f",s/v,l/v);
  41.     fclose(dat);
  42.     return 0;
  43. }
  44.  
Add Comment
Please, Sign In to add comment