Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main (int argc, char *argv[])
- {
- char c;
- char soubor[128];
- unsigned int x;
- FILE *r;
- int pocet_vyskytu = 0, pocet = 0, znak;
- system("cls");
- printf("\n\n --==Toto je funkce na porovnavani sekvence znaku v souboru==--\n\n");
- if (argc != 3)
- {
- printf(" Vase zadani parametru bylo nepresne, \nzadejte prosim parametry rucne: \n");
- printf ("\n Zadejte hledany znak:\n> ");
- scanf("%c", &c);
- printf("\n Zadejte pocet vyskytu:\n> ");
- scanf("%u", &x);
- printf("\n Zadejte nazev souboru:\n> ");
- scanf("%128s", soubor);
- if ((r = fopen(soubor, "r")) == NULL)
- {
- printf ("Soubor %s se nepodario otevrit.\n", soubor);
- system("pause");
- return 0;
- }
- }
- else
- {
- if (argc > 4)
- {
- printf("\n To je moc parametru");
- system("pause");
- return 0;
- }
- if ((r = fopen(argv[1], "r")) == NULL)
- {
- printf ("\n Soubor %s se nepodario otevrit.\n", argv[1]);
- system("pause");
- return 0;
- }
- c = argv[2][0];
- x = (unsigned)atoi(argv[3]);
- }
- while(!feof(r))
- {
- znak = getc(r);
- if (znak == '\n' || znak == EOF)
- {
- if (pocet >= x)
- pocet_vyskytu++;
- pocet = 0;
- }
- if ((char)znak == c)
- {
- pocet++;
- }
- }
- printf ("Uvedeny znak %c se vyskytuje celkem %d-krat\n", c, pocet_vyskytu);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement