Advertisement
18126

Day5(ex5)

Jul 9th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <Windows.h>
  4. #include <string.h>
  5.  
  6. void print(char o[], int len) {
  7.     for(int j = 0; j < len; j++) {
  8.         printf("%c", o[j]);
  9.     }
  10.     printf("\n");
  11. }
  12.  
  13. int check(char c[], int len) {
  14.     int found1 = 0, found2 = 0, found3 = 0;
  15.     for(int i = 0; i < len; i++) {
  16.         if(found3 == 1) {
  17.             if(c[i] == 'o' || c[i] == 'O') {
  18.                 return 1;
  19.             }
  20.             else {
  21.                 found1 = 0;
  22.                 found2 = 0;
  23.                 found3 = 0;
  24.                 continue;
  25.             }
  26.         }
  27.         else if(found2 == 1) {
  28.             if(c[i] == 'n' || c[i] == 'N') {
  29.                 found3 = 1;
  30.                 found2 = 0;
  31.             } else {
  32.                 found1 = 0;
  33.                 found2 = 0;
  34.                 continue;
  35.             }
  36.         }
  37.         else if(found1 == 1) {
  38.             if(c[i] == 'a' || c[i] == 'A') {
  39.                 found2 = 1;
  40.                 found1 = 0;
  41.             } else {
  42.                 found1 = 0;
  43.                 continue;
  44.             }
  45.         }
  46.         else {
  47.             if(c[i] == 'n' || c[i] == 'N') {
  48.                 found1 = 1;
  49.             }
  50.         }
  51.     }
  52.     return 0;
  53. }
  54.  
  55. int main() {
  56.     char a[11] = "Hellonano !";
  57.     char b[8] = "Hellona!";
  58.     char c[10] = "HelloNaNo!";
  59.     printf("0: Doesn't contain the word\n1: Does contain the word\n=========\n");
  60.     print(a, 11);
  61.     printf("Text 1: %d\n\n", check(a, 11));
  62.     print(b, 8);
  63.     printf("Text 2: %d\n\n", check(b, 8));
  64.     print(c, 10);
  65.     printf("Text 3: %d\n\n", check(c, 10));
  66.     return EXIT_SUCCESS;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement