Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int findSeq(){
  5.   char charArray[] = {"0000110"};
  6.   int pos = 0;  //pos in array
  7.   int found = 0;
  8.  
  9.   char curr;
  10.  
  11.   int flag = 1;
  12.  
  13.   while (flag != EOF){
  14.     flag = scanf("%c%*c", &curr); //grab user's input
  15.     //printf("Users input: %c\n", curr); //print user's input
  16.     //printf("Array pos: %c\n", charArray[pos]); //print current position in array
  17.  
  18.     if(curr == charArray[pos]){
  19.       pos++;
  20.     } else{
  21.       pos=0;
  22.     }
  23.  
  24.    
  25.  
  26.     if (pos == 3){
  27.       pos = 0;
  28.       found++;
  29.     }
  30.  
  31.   }
  32.  
  33.   return found;
  34. }
  35.  
  36.  
  37. int main(){
  38.   printf("Found: %d\n", findSeq());
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement