Featured
- Get link
- X
- Other Apps
C++ program to check substring of string
#include <iostream.h>
int main()
{
char a[100],b[100];
int k=0,j=0,flag=1,i;
cout<<"enter a string : ";
cin.getline(a, 100);
cout<<"\nenter another string : ";
cin.getline(b, 100);
for(j = 0;a[j]!='\0';j++) {
if(a[j]==b[0]) {
i = j;
for(j , k = 0; b[k]!='\0';j++,k++) {
if(a[j]==b[k]) {
flag = 1;
} else {
j = i++;
flag = 0;
break;
}
}
}
}
if(flag == 1) {
cout<<"\n"<<b<<" "<<"is a substring of"<<" "<<a;
} else {
cout<<"\nmy"<<b<<" "<<"is not a substring of"<<" "<<a;
}
return 0;
}
int main()
{
char a[100],b[100];
int k=0,j=0,flag=1,i;
cout<<"enter a string : ";
cin.getline(a, 100);
cout<<"\nenter another string : ";
cin.getline(b, 100);
for(j = 0;a[j]!='\0';j++) {
if(a[j]==b[0]) {
i = j;
for(j , k = 0; b[k]!='\0';j++,k++) {
if(a[j]==b[k]) {
flag = 1;
} else {
j = i++;
flag = 0;
break;
}
}
}
}
if(flag == 1) {
cout<<"\n"<<b<<" "<<"is a substring of"<<" "<<a;
} else {
cout<<"\nmy"<<b<<" "<<"is not a substring of"<<" "<<a;
}
return 0;
}
- Get link
- X
- Other Apps
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment