this program will replace a substring from the string with a new string . It is working perfect ...
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream.h>
char *replace(char *st, char *orig, char *repl)
{
char buff[50];
char *ch;
if ( !( ch = strstr( st, orig ) ) )
return st;
strncpy(buff, st, ch-st);
buff[ch-st] = 0;
sprintf(buff+(ch-st), "%s%s", repl, ch+strlen(orig));
return buff;
}
void main()
{
clrscr();
char s[20],s1[30],s3[40];
cout<< " Enter the String ";
gets(s);
cout<<" Enter the string to replace ";
gets(s1);
cout<<"Enter new string";
gets(s3);
puts(replace(s, s1, s3));
getch();
}
help me to do this without using any string Library functions and in simple mode. please help me...