Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <Windows.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <stdbool.h>
  8. int main()
  9. {
  10.     bool InWord = false;
  11.     char s[256], word[30], searchWord[30];
  12.     int i = 0, j = 0, err, count = 0, count1 = 0;
  13.     SetConsoleOutputCP(1251);
  14.     do
  15.     {
  16.         printf("\nВъведете търсена дума: ");
  17.         err = scanf("%s", searchWord);
  18.         while (getchar() != '\n');
  19.     } while (err != 1);
  20.     printf("\nВъведете низ: ");
  21.     if (fgets(s, 254, stdin) != s)
  22.     {
  23.         printf("\nГрешка!");
  24.         exit(1);
  25.     }
  26.     for (i = 0, j = 0; s[i]; i++)
  27.     {
  28.  
  29.         if (InWord == false)
  30.         if (!isspace(s[i]))
  31.         {
  32.             InWord = true;
  33.             word[j++] = s[i];
  34.         }
  35.         else
  36.             continue;
  37.         else
  38.         if (isspace(s[i]))
  39.         {
  40.             InWord = false;
  41.             word[j] = '\0';
  42.             count++;
  43.             printf("\n%s", word);
  44.             if (strcmp(word, searchWord) == 0)
  45.                 count1++;
  46.             j = 0;
  47.         }
  48.         else
  49.             word[j++] = s[i];
  50.     }
  51.     printf("\nCount= %d", count);
  52.     printf("\nCount1= %d\n", count1);
  53.     system("pause");
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement