Monday, August 3, 2009

Find and replace program

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char nam[50][50],sea[50];
int i,k=0,j,n;
int f=1;
char nam1[50];
clrscr();
printf("ENTER THE NO. OF NAMES\n");
scanf("%d",&n);
printf("ENTER THE NAME\n");
for(i=1;i<=n;i++)
{
scanf("%s",nam[i]);
}
/*internal*/
printf("memory\n");
for(i=1;i<=n;i++)
puts(nam[i]);
printf("\nENTER NAME TO BE replace\n\t\t");
scanf("%s",sea);

printf("........searching .....\n\t");
j=1;
while(j<=n)
{
if(strcmp(nam[j],sea)==0)
{
printf("\n\n\n===========found==============\n\n\n\n\n");
/*replacing */
printf("ENTER THE NAME WANT TO BE insert\n\t\n");
scanf("%s",nam1);
strcpy(nam[j],nam1);
f=0;
j=j+n;
}
else
j++;
}
if(!f)
{
printf("-----------------------------\n\n\n");
printf("displaying names\n\n\n\n");
for(k=1;k<=n;k++)
{ printf("no %d \t is ",k); puts(nam[k]);
}
}
else
{
printf("not found") ;
}
getch();
}

output:

ENTER THE NO. OF NAME

2

ENTER THE NAME

KARTHI

KARTHIKEYAN

memory

KARTHI

KARTHIKEYAN

ENTER THE NAME WANT TO BE replace

KARTHI

...............searching...............

==========found=========

ENTER THE NAME WANT TO BE insert

KARTHIKEN07@GMAIL.COM

..........................................

displaying names

NO 1 IS KARTHIKEN07@GMAIL.COM

NO 2 IS KARTHIKEYAN

No comments:

Post a Comment