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>
- #include <Windows.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdbool.h>
- int main()
- {
- bool InWord = false;
- char s[256], word[30], searchWord[30];
- int i = 0, j = 0, err, count = 0, count1 = 0;
- SetConsoleOutputCP(1251);
- do
- {
- printf("\nВъведете търсена дума: ");
- err = scanf("%s", searchWord);
- while (getchar() != '\n');
- } while (err != 1);
- printf("\nВъведете низ: ");
- if (fgets(s, 254, stdin) != s)
- {
- printf("\nГрешка!");
- exit(1);
- }
- for (i = 0, j = 0; s[i]; i++)
- {
- if (InWord == false)
- if (!isspace(s[i]))
- {
- InWord = true;
- word[j++] = s[i];
- }
- else
- continue;
- else
- if (isspace(s[i]))
- {
- InWord = false;
- word[j] = '\0';
- count++;
- printf("\n%s", word);
- if (strcmp(word, searchWord) == 0)
- count1++;
- j = 0;
- }
- else
- word[j++] = s[i];
- }
- printf("\nCount= %d", count);
- printf("\nCount1= %d\n", count1);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement