rajeevs1992

Auto Complete

Apr 23rd, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<iostream.h>
  4. #include<process.h>
  5. #include<conio.h>
  6. void search(int n);
  7. void print(char temp[50],int i,int n);
  8. char str[50][50];
  9. int main()
  10. {
  11.     int n;
  12.     cout<<"\nEnter the no of words ";
  13.     cin>>n;
  14.     for(int i=0;i<n;i++)
  15.     {
  16.         cout<<"\nEnter word no "<<(i+1)<<" ";
  17.         gets(str[i]);
  18.     }
  19.     search(n);
  20.    return 0;
  21. }
  22.  
  23. void search(int n)
  24. {
  25.     char temp[50],ch;
  26.     int i=0;
  27.     clrscr();
  28.     cout<<"\nEnter string to search ";
  29.     while(1)
  30.     {
  31.         ch=getch();
  32.         clrscr();
  33.         if(ch!='~')
  34.         {
  35.             if((int)ch==8)
  36.             {
  37.                 i=i-1;
  38.                 if(i<0)
  39.                 i=0;
  40.                 temp[i]='\0';
  41.             cout<<"\nEnter string to search ";
  42.                 puts(temp);
  43.                 print(temp,i-1,n);
  44.             }
  45.             else
  46.             {
  47.                 temp[i]=ch;
  48.                 temp[i+1]='\0';
  49.                 cout<<"\nEnter string to search ";
  50.                 puts(temp);
  51.                 print(temp,i,n);
  52.                 i++;
  53.             }
  54.         }
  55.         else
  56.             exit(0);
  57.     }
  58. }
  59.  
  60. void print(char temp[50],int i,int n)
  61. {
  62.     int f=1;
  63.     for(int a=0;a<n;a++)
  64.     {
  65.     f=1;
  66.         for(int b=0;b<=i;b++)
  67.         {
  68.             if(str[a][b]!=temp[b])
  69.             {
  70.                 f=0;
  71.                 break;
  72.             }
  73.         }
  74.         if(f == 1)
  75.         {
  76.             puts(str[a]);
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment