Advertisement
LegoDrifter

Datoteki - 15/ Zadaca 3

Jun 17th, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<ctype.h>
  4. #include <ctype.h>
  5.  
  6. int samoglaska(char c)
  7. {
  8.     c=tolower(c);
  9.     if(c == 'a' || c == 'e' || c == 'i' || c =='o' || c =='u')
  10.     return 1;
  11.     else return 0;
  12.  
  13. }
  14.  
  15. int broenjeSamoglaski(char *c)
  16. {
  17.     int brojac=0;
  18.     for(int i=0;i<strlen(c);i++)
  19.     {
  20.         if(samoglaska(c[i]))
  21.             brojac++;
  22.     }
  23.     return brojac;
  24. }
  25.  
  26. void writeToFile() {
  27.     FILE *f = fopen("dat.txt", "w");
  28.     char c;
  29.     while((c = getchar()) != '#') {
  30.         fputc(c, f);
  31.     }
  32.     fclose(f);
  33. }
  34.  
  35.  
  36.  
  37. int main () {
  38.  
  39.     writeToFile();
  40.  
  41.     FILE *f1 = fopen("dat.txt","r");
  42.     char ch;
  43.     char zborce[100];
  44.     int flag=0,max=0;
  45.     int brojac=0;
  46.     char nova[100];
  47.     while((ch=fgetc(f1))!=EOF)
  48.     {
  49.         if(isalpha(ch))
  50.         {
  51.             if(!flag)
  52.             {
  53.                 flag=1;
  54.             }
  55.             nova[brojac]=ch;
  56.             brojac++;
  57.         }
  58.         else if(flag)
  59.         {
  60.             nova[brojac]='\0';
  61.             flag=0;
  62.             if(broenjeSamoglaski(nova)>=max)
  63.             {
  64.                 max=broenjeSamoglaski(nova);
  65.                 strcpy(zborce,nova);
  66.  
  67.  
  68.             }
  69.             brojac=0;
  70.  
  71.  
  72.         }
  73.     }
  74.  
  75.     if(max==0)
  76.     {
  77.         printf("Nema nitu eden zbor so samoglaska");
  78.     }
  79.     else
  80.     {
  81.     printf("%s",zborce);
  82.     printf(" %d",max);
  83.     }
  84.  
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement