Hello friends,today i share a program which i made in 4hours but with my own hardwork,i am sure that you can easily understand this program because i make this program only for my friends,please read it carefully try to understand it.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100],sub[100];
int i,j,k,l,f=0,g=0,m,h,v;
clrscr();
printf("\n Enter the string:");
gets(str);
printf("\n Enter the substring:");
gets(sub);
l=strlen(sub);
m=strlen(str);
printf("%d %d",l,m);
for(i=0;str[i]!='\0';i++)
{
k=i;
j=0;
while(sub[j]!='\0')
{
if(str[k]==sub[j])
{
g++;
if(g==l)
{
f=1;
h=i;
}
}
else if(str[k]!=sub[j])
{
break;
}
j++;
k++;
}
}
if(f==1)
{
printf("\n sub string is found\n\n\n");
for(i=0;i<m;i++)
{
if(i<h)
printf("%c",str[i]);
else if(i>h&&i<(h+l))
continue;
else if(i>(h+l))
printf("%c",str[i]);
}
}
else if(f==0)
{
printf("\n substring not found:");
}
getch();
return(0);
}
Thanking You Guys........
good
ReplyDeleteThanks :)
ReplyDeleteGood
ReplyDeletenice, but you are just printing the string leaving the substring present in it, how can you change the main string itself by deleting the substring from it? i am guessing by using a[pos] = a[pos+1] as many times as the substring length starting from the first position of the substring in the string, what do you think?
ReplyDeleteBut why doing a program with so many variables.
ReplyDeleteYour code is not too perfect there is lots of bug in your code .
ReplyDeleteYou are not deleting the multiple occurrence and statements like souravis he is a boy will give a output like sourav he is a boy that is not correct..
Great Blog...
ReplyDeleteBest Web technology website to learn CRUD operation in node.js express
crud operation in php
PHP Inerview Questions and Answers
multiple file upload in node.js and express
Form validation in node.js
How to prevent mysql in php
autocomplete search in php