Advertisement
imtiazaasif

Regular expression

Nov 26th, 2021
1,158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<string.h>
  3.  
  4.  
  5. int main(){
  6.     int i,state_a=0,state_b,state_n;
  7.     char s[100];
  8.     printf("Enter your string");
  9.     gets(s);
  10.     int len=strlen(s);
  11.  
  12.     for(i=0;i<len;i++){
  13.         if(s[i]=='a')
  14.         {
  15.             state_a=state_a+1;
  16.         }
  17.         else if(s[i]=='b'){
  18.             if((s[i+1])=='a'){
  19.                 state_n=1;
  20.                 break;
  21.             }
  22.             else(state_b=state_b+1);
  23.         }
  24.         else if(s[i]!='a' || s[i]!='b')
  25.         {
  26.             state_n=1;
  27.             break;
  28.         }
  29.         else
  30.             continue;
  31.     }
  32.     if(state_a==len)
  33.     {
  34.         printf("the string is not recognised");
  35.     }
  36.     else if(state_b==len)
  37.     {
  38.         printf("the string is recognised under the 'a*b+'");
  39.     }
  40.     else if(state_n==1){
  41.          printf("the string is not recognised");
  42.     }
  43.     else
  44.     {
  45.         printf("the string is recognised under the 'a*b+'");
  46.     }
  47.  
  48.     getch();
  49. }
  50.  
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement