Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SUBOR "ZNAKY.TXT"
- int cislica(char c);
- int male_pismeno(char c);
- int velke_pismeno(char c);
- int biely(char c);
- void zisti(int (*p_func)(), FILE *file);
- int main(void)
- {
- FILE *file = fopen(SUBOR, "r");
- int n = 0;
- char vyber;
- if (file == NULL)
- {
- fprintf(stderr, "Chyba pri otvarani suboru s menom: %s\n", SUBOR);
- exit(1);
- }
- rewind(file);
- while(1)
- {
- scanf("%d", &n);
- if(n > 4)
- {
- fprintf(stderr, "Bol zadany vacsi pocet, nez sa da. Maximum co mozete zadat, je 4.\n");
- continue;
- }
- else
- {
- break;
- }
- }
- getchar();
- for(n; n > 0; n--)
- {
- vyber = getchar();
- getchar();
- if(vyber == 'b')
- {
- zisti(biely, file);
- }
- else if(vyber == 'v')
- {
- zisti(velke_pismeno, file);
- }
- else if(vyber == 'm')
- {
- zisti(male_pismeno, file);
- }
- else if(vyber == 'c')
- {
- zisti(cislica, file);
- }
- }
- if (fclose(file) == EOF)
- {
- fprintf(stderr, "Chyba pri zatvarani suboru s menom: %s\n", SUBOR);
- exit(1);
- }
- return 0;
- }
- void zisti(int (*p_func)(), FILE *file)
- {
- int occur = 0;
- while(!feof(file))
- {
- if(p_func(fgetc(file)))
- {
- occur++;
- }
- }
- printf("%d\n", occur);
- rewind(file);
- }
- int cislica(char c)
- {
- return (c <= '9' && c >= '0');
- }
- int male_pismeno(char c)
- {
- return (c <= 'z' && c >='a');
- }
- int velke_pismeno(char c)
- {
- return (c <= 'Z' && c >= 'A');
- }
- int biely(char c)
- {
- return (c <= ' ');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement