Skip to content

Instantly share code, notes, and snippets.

@rajeevs1992
Created January 22, 2013 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeevs1992/4595160 to your computer and use it in GitHub Desktop.
Save rajeevs1992/4595160 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<process.h>
#include<conio.h>
void search(int n);
void print(char temp[50],int i,int n);
char str[50][50];
int main()
{
int n;
cout<<"\nEnter the no of words ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\nEnter word no "<<(i+1)<<" ";
gets(str[i]);
}
search(n);
return 0;
}
void search(int n)
{
char temp[50],ch;
int i=0;
clrscr();
cout<<"\nEnter string to search ";
while(1)
{
ch=getch();
clrscr();
if(ch!='~')
{
if((int)ch==8)
{
i=i-1;
if(i<0)
i=0;
temp[i]='\0';
cout<<"\nEnter string to search ";
puts(temp);
print(temp,i-1,n);
}
else
{
temp[i]=ch;
temp[i+1]='\0';
cout<<"\nEnter string to search ";
puts(temp);
print(temp,i,n);
i++;
}
}
else
exit(0);
}
}
void print(char temp[50],int i,int n)
{
int f=1;
for(int a=0;a<n;a++)
{
f=1;
for(int b=0;b<=i;b++)
{
if(str[a][b]!=temp[b])
{
f=0;
break;
}
}
if(f == 1)
{
puts(str[a]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment