Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<conio.h>
- #define pf printf
- #define sf scanf_s
- int begins(char s[],char t[])
- {
- int i,z=0,count=0;
- for(i=0;i<strlen(t);i++)
- if(s[i]==t[i])
- count++;
- if(count==strlen(t))
- z=1;
- return z;
- }
- int beginsor(char s[],char t[],char u[])
- {
- int z=0,i,k;
- i = begins(s,t);
- k = begins(s,u);
- if(i==1||k==1)
- z=1;
- return 1;
- }
- int notbegins(char s[],char t[])
- {
- int z=0,i;
- i = begins(s,t);
- if(i==0)
- z=1;
- return z;
- }
- int ends(char s[],char t[])
- {
- int i,k=0,slen,z=0,count=0;
- slen = strlen(s)-strlen(t);
- for(i=slen;i<strlen(s);i++)
- {
- if(s[i]==t[k])
- count++;
- k++;
- }
- if(count==strlen(t))
- z=1;
- return z;
- }
- int endsor(char s[],char t[],char u[])
- {
- int z=0,i,k;
- i = ends(s,t);
- k = ends(s,u);
- if(i==1||k==1)
- z=1;
- return 1;
- }
- int notends(char s[],char t[])
- {
- int z=0,i;
- i = ends(s,t);
- if(i==0)
- z=1;
- return z;
- }
- int contains(char s[],char t[])
- {
- int i,j,k=0,z=0,count=0;
- for(i=0;i<strlen(s);i++)
- {
- if(s[i]==t[k])
- {
- for(j=k;j<(strlen(t)-1);j++)
- {
- if(s[++i]=t[j])
- count++;
- }
- }
- }
- if(count==(strlen(t)-1))
- z=1;
- return z;
- }
- int notcontains(char s[],char t[])
- {
- int z=0,i;
- i = contains(s,t);
- if(i==0)
- z=1;
- return z;
- }
- int beginandend(char s[],char t[],char u[])
- {
- int i,j,z=0;
- i = begins(s,t);
- j = ends(s,u);
- if(i==1&&j==1)
- z=1;
- return z;
- }
- int doesnotbeginandend(char s[],char t[],char u[])
- {
- int z=0,i;
- i = beginandend(s,t,u);
- if(i==0)
- z=1;
- return z;
- }
- int main()
- {
- char s[100],t[100],u[100];
- int ch,z;
- pf("Enter string 1 \n");
- gets_s(s);
- pf("\nEntered string is given below\n");
- pf("%s",s);
- while(1)
- {
- pf("\n\n\nEnter choice \n1.Set of strings begins with ?\n2.Set of strings doesn't begins with ?");
- pf("\n3.Set of strings that end with ?\n4.Set of strings that doesn't end with ?\n5.Set of strings that contains ?");
- pf("\n6.Set of strings that doesn't contains ?\n7.Set of strings that starts with ? and ends with ?");
- pf("\n8.Set of strings that doesn't starts with ? and ends with ?");
- pf("\n9.Set of strings that begins with ? or ?");
- pf("\n10.Set of strings that ends with ? or ?\n11.Exit\n");
- sf("%d",&ch);
- if(ch==11)
- break;
- z=0;
- switch(ch)
- {
- case 1:pf("Enter string 2\n");
- scanf_s("%s",t);
- z = begins(s,t);
- break;
- case 2:pf("Enter string 2\n");
- scanf_s("%s",t);
- z = notbegins(s,t);
- break;
- case 3:pf("Enter string 2\n");
- scanf_s("%s",t);
- z = ends(s,t);
- break;
- case 4:pf("Enter string 2\n");
- scanf_s("%s",t);
- z = notends(s,t);
- break;
- case 5:pf("Enter string 2\n");
- scanf_s("%s",t);
- z = contains(s,t);
- break;
- case 6:pf("Enter string 2\n");
- scanf_s("%s",t);
- z = notcontains(s,t);
- break;
- case 7:pf("Enter string 2\n");
- scanf_s("%s",t);
- pf("Enter string 3\n");
- scanf_s("%s",u);
- z = beginandend(s,t,u);
- break;
- case 8:pf("Enter string 2\n");
- scanf_s("%s",t);
- pf("Enter string 3\n");
- scanf_s("%s",u);
- z = doesnotbeginandend(s,t,u);
- break;
- case 9:pf("Enter string 2\n");
- scanf_s("%s",t);
- pf("Enter string 3\n");
- scanf_s("%s",u);
- z = beginsor(s,t,u);
- break;
- case 10:pf("Enter string 2\n");
- scanf_s("%s",t);
- pf("Enter string 3\n");
- scanf_s("%s",u);
- z = endsor(s,t,u);
- break;
- default:pf("\nInvalid input");
- }
- if(z==1)
- pf("\nEntered string will be accepted by the Machine");
- else
- pf("\nEntered string will not be accepted by the Machine");
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement