Q.Write a function to accept a main string, one search string and one replace string. Replace the first occurence of search string in main string by replace string{assume the length of search and replace string is same).
Solution I tried
#include<stdio.h>
#include<conio.h>
void main()
{
char mai[80],search[40],replace[40];
int i,j,k,l;
printf("Enter main string\n");
gets(mai);
printf("Enter search string\n");
gets(search);
printf("Enter replace string(same len as search)\n");
gets(replace);
for(i=0;mai!='\0',search!='\0';i++)
{
if(mai[i]==search[0])
{
for(j=i+1,k=1,l=0;mai!='\0',search!='\0',replace!='\0';j++,k++,l++)
{
if(mai[j]==search[k])
{
mai[j-1]=replace[l];
}
}
}
}
printf("New string is %s\n",mai);
}
I am not gettin the desired output. And what does it mean by first occurence of search string? Does it mean the whole string or first letter of search string? HELP!!:confused: :sad: