#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char a[100],b[50],c[50];
int i,n,j,k,d;
printf("enter the string: ");
fgets(a,sizeof(a),stdin);
printf("enter the string to be removed: ");
fgets(b,sizeof(b),stdin);
printf("enter the string to be searched: ");
fgets(c,sizeof(c),stdin);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==b[0])
{
k=i;
printf(" \n the first character is at %d",k);
printf("\n lets see whelther searchstring is available");
for(k=i,j=0;a[k]!='\0',b[j]!='\0';k++,j++)
{
if(a[k]==b[j])
{
for(d=0;c[d]='\0';d++)
{
a[k]=c[d];
}
}
}
}
}
for(i=0;a[i]!='\0';i++)
{
printf("%s",a[i]);
}
}
i know there is lot of mistake here but i dont know where is logical mistake please modify my mistakes
}
rithish
13
Junior Poster in Training
Recommended Answers
Jump to PostI don't particularly like how you're trying to lump everything together because it complicates an already complicated algorithm. There are three separate parts to replacing a substring:
- Find a matching substring.
- Make room for the replacement.
- Insert the replacement.
Separating the tasks conceptually will help you write code that …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.