String matching

 #include<stdio.h>

 

int main()

{

    char str[80];

    int count1 = 0, count2 = 0, i, j;

    char start , end ; 

    printf("Enter a string:");

    gets(str);

    printf("enter first character\n");

    scanf(" %c", &start);


     printf("enter 2nd character\n");

    scanf(" %c", &end);

    while (str[count1] != '\0')

        count1++;

   

    for (i = 0; i <= count1 ; i++)

    {

        for (j = count1; j > i ; j--) {

            

                if( (str[i]== start && str[j]== end) || ( str[i]== end && str[j]== start)){

                count2++;

              for(int k = i ; k <= j ; k++){

              printf("%c",str[k]);

              }

              printf("\n");  

                }

        }

     

    }

    printf("total count is %d",count2);

 

    return 0;

}

Comments

Popular posts from this blog

DAA P4 bfs, dfs

DAA P8 graph coloring

Practical 8 by Karan