Advertisement
18126

Day5(ex6)

Jul 9th, 2021
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 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 count(char c[], int len) {
  14.     int found1 = 0, found2 = 0, found3 = 0, counter = 0;
  15.     for(int i = 0; i < len; i++) {
  16.         if(found3 == 1) {
  17.             if(c[i] == 'o' || c[i] == 'O') {
  18.                 counter += 1;
  19.                 found3 = 0;
  20.                 continue;
  21.             }
  22.             else {
  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.                 found2 = 0;
  33.                 continue;
  34.             }
  35.         }
  36.         else if(found1 == 1) {
  37.             if(c[i] == 'a' || c[i] == 'A') {
  38.                 found2 = 1;
  39.                 found1 = 0;
  40.             } else {
  41.                 found1 = 0;
  42.                 continue;
  43.             }
  44.         }
  45.         else {
  46.             if(c[i] == 'n' || c[i] == 'N') {
  47.                 found1 = 1;
  48.             }
  49.         }
  50.     }
  51.     return counter;
  52. }
  53.  
  54. int main() {
  55.     char a[46] = "HellonanonanoNANO n ANO !";
  56.     char b[8] = "Hellona!";
  57.     char c[18] = "HelloNaNonanoNoNo!";
  58.     print(a, 46);
  59.     printf("Count for text 1: %d\n\n", count(a, 46));
  60.     print(b, 8);
  61.     printf("Count for text 2: %d\n\n", count(b, 8));
  62.     print(c, 18);
  63.     printf("Count for text 3: %d\n\n", count(c, 18));
  64.     return EXIT_SUCCESS;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement