Dimitrija

Laboratoriski ISPITNI - 1 SP

Jan 5th, 2021 (edited)
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #define MAX 1000
  5.  
  6. /*
  7.  
  8. Дадена е текстуална датотека text.txt.
  9.  
  10. Да се избројат и испечатат сите последнователни појавувања на соседни самогласки во датотеката. Појавата на големи и мали букви да се игнорира. Пронајдените парови самогласки да се испечатат на екран, секој во нов ред со мали букви. Потоа во нов ред се печати бројот на појавувања на паровите самогласки.
  11.  
  12. Пример: за датотеката:
  13.  
  14. IO is short for Input Output
  15. medioio medIo song
  16.  
  17. излез:
  18.  
  19. io
  20. ou
  21. io
  22. oi
  23. io
  24. io
  25. 6
  26. For example:
  27.  
  28. Input             Result
  29. Why so serious?     io
  30. #                   ou
  31.                     2
  32.  
  33.                
  34. */
  35.  
  36.  
  37.  
  38.  
  39.  
  40. void writeToFile() {
  41.   FILE *f = fopen("text.txt", "w");
  42.   char c;
  43.   while((c = getchar()) != '#') {
  44.     fputc(c, f);
  45.   }
  46.   fclose(f);
  47. }
  48.  
  49. int main() {
  50.    
  51.   writeToFile();
  52.    
  53.   FILE *dat;
  54.  
  55.   if ((dat=fopen("text.txt","r"))==NULL){
  56.     fprintf(stderr,"ERROR DURING OPENING");
  57.     return -1;
  58.   }
  59.    
  60.     char niza[MAX];
  61.     char c;
  62.    
  63.     int isvowel=0;
  64.     char prev;
  65.     int cnt=0;
  66.    
  67.     while((c=fgetc(dat)) != EOF){
  68.         if (tolower(c) == 'a' || tolower(c) == 'e' || tolower(c) == 'i' || tolower(c) == 'i' || tolower(c) == 'o' || tolower(c) == 'u'){
  69.             if (isvowel == 1){
  70.                 printf("%c%c\n",tolower(prev),tolower(c));
  71.                 prev = c;
  72.                 cnt++;
  73.                
  74.             }
  75.             else{
  76.                 isvowel=1;
  77.                 prev = c;
  78.             }
  79.            
  80.         }
  81.         else{
  82.             isvowel =0;
  83.         }
  84.        
  85.     }
  86.     printf("%d",cnt);
  87.  
  88.   return 0;
  89. }
  90.  
Add Comment
Please, Sign In to add comment