Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- int countAB(int c, int *status);
- int Automat(int c, int *status);
- int main()
- {
- FILE *input;
- int c, status = 0;
- char fName[32];
- int count = 0;
- printf("Enter name: ");
- scanf("%s", &fName);
- if (!(input = fopen(fName, "r")))
- {
- printf("The file does not exist.\n");
- system("pause");
- exit(1);
- }
- while ((c = fgetc(input)) != EOF)
- {
- //status = Automat(c, &status);
- status = countAB(c, &status);
- if (status == 2)
- {
- count++;
- status = 0;
- }
- }
- printf("Found matches: %d\n", count);
- if (input)
- fclose(input);
- system("pause");
- return 0;
- }
- int countAB(int c, int *status)//търси колко пъти се среща 'аb' във файлът
- {
- switch (*status)
- {
- case 0:
- if (c == 'a')
- *status = 1;
- break;
- case 1:
- if (c == 'b')
- {
- *status = 2;
- }
- else
- {
- *status = 0;
- }
- break;
- }
- return *status;
- }
- int Automat(int c, int *status) //търси колко пъти се среща '11' във файлът
- {
- switch (*status)
- {
- case 0:
- if (c == '1')
- {
- *status = 1;
- }
- break;
- case 1:
- if (c == '1')
- {
- *status = 2;
- }
- else
- {
- *status = 0;
- }
- break;
- }
- return *status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement