Showing posts with label
C Program TO REPLACE A PARTICULAR WORD BY ANOTHER WORD IN GIVEN STRING.
Show all posts
Showing posts with label
C Program TO REPLACE A PARTICULAR WORD BY ANOTHER WORD IN GIVEN STRING.
Show all posts
C Program TO REPLACE A PARTICULAR WORD BY ANOTHER WORD IN GIVEN STRING
#include
#include
main()
{
int lr,m,x,t,l,ll,ls,i,j,k,flag,count=0;
char line[200],str[20],rep[20];
printf(“Enter line of text\n”);
gets(line);
printf(“Enter the word to replace\n”);
scanf(“%s”,str);
printf(“Enter the word to replace with\n”);
scanf(“%s”,rep);
ll=strlen(line);
ls=strlen(str);
lr=strlen(rep);
for(i=0;i<ll;i++)
{
if(line[i]==str[0]&&((line[i-1]==’ ‘||i==0)&&(line[i+ls]==’ ‘||line[i+ls]==’\0′)))
{
for(flag=0,k=i,j=0;j{
if(line[k]==str[j])
{
flag++;
}
}
if(flag==ls)
{
if(lr>ls)
{
for(m=lr-ls;m>0;m–)
{
ll=strlen(line);
for(l=ll;l>i;l–)
{
line[l+1]=line[l];
}
}
}
else if(lr{
for(m=ls-lr;m>0;m–)
{
ll=strlen(line);
for(l=i;l<ll;l++)
{
line[l]=line[l+1];
}
}
}
else
{
}
for(x=0,t=i;x<lr;x++,t++)
{
line[t]=rep[x];
}
}
}
}
printf(“Text\n”);
puts(line);
}
Output :
Enter line of text
Snehal IS A GOOD GIRL
Enter the word to replace
GIRL
Enter the word to replace with
BOY
Text
Snehal IS A GOOD BOY
Related Links :
History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}
Next Step...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");
getch ();
}