Advertisement
Guest User

Untitled

a guest
May 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main (int argc, char *argv[])
  5. {
  6.     char c;
  7.     char soubor[128];
  8.     unsigned int x;
  9.     FILE *r;
  10.     int pocet_vyskytu = 0, pocet = 0, znak;
  11.  
  12.  
  13.     system("cls");
  14.     printf("\n\n --==Toto je funkce na porovnavani sekvence znaku v souboru==--\n\n");
  15.     if (argc != 3)
  16.     {
  17.         printf(" Vase zadani parametru bylo nepresne, \nzadejte prosim parametry rucne: \n");
  18.         printf ("\n Zadejte hledany znak:\n> ");
  19.         scanf("%c", &c);
  20.         printf("\n Zadejte pocet vyskytu:\n> ");
  21.         scanf("%u", &x);
  22.         printf("\n Zadejte nazev souboru:\n> ");
  23.         scanf("%128s", soubor);
  24.  
  25.         if ((r = fopen(soubor, "r")) == NULL)
  26.         {
  27.         printf ("Soubor %s se nepodario otevrit.\n", soubor);
  28.         system("pause");
  29.         return 0;
  30.         }
  31.     }
  32.     else
  33.     {
  34.         if (argc > 4)
  35.         {
  36.             printf("\n To je moc parametru");
  37.             system("pause");
  38.             return 0;
  39.         }
  40.         if ((r = fopen(argv[1], "r")) == NULL)
  41.         {
  42.             printf ("\n Soubor %s se nepodario otevrit.\n", argv[1]);
  43.             system("pause");
  44.             return 0;
  45.         }
  46.         c = argv[2][0];
  47.         x = (unsigned)atoi(argv[3]);
  48.        
  49.     }
  50.  
  51.    
  52.  
  53.     while(!feof(r))
  54.     {
  55.         znak = getc(r);
  56.  
  57.         if (znak == '\n' || znak == EOF)
  58.         {
  59.             if (pocet >= x)
  60.                 pocet_vyskytu++;
  61.             pocet = 0;
  62.         }
  63.         if ((char)znak == c)
  64.         {
  65.             pocet++;
  66.         }
  67.     }
  68.  
  69.     printf ("Uvedeny znak %c se vyskytuje celkem %d-krat\n", c, pocet_vyskytu);
  70.     system("pause");
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement