Friday, October 2, 2015

Small Search-For Beginers In C

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
void main()
{
     int i,j;
     int n=0,N,t;
  struct search
   {
       char name[10][25],na[25],temp[25];
       int age,dob;
   }s,s1[2];
 clrscr();
 printf("Enter the names below ");
 printf("\n NOTE:TYPE 0 WHEN FINISHED\n");
 do
  {
   scanf("%s",s1[n].name[n]);
   }while(strcmp(s1[n].name[n++],"0"));
 clrscr();
 for(i=0;i<n-1;i++)
 {
    for(j=i+1;j<n;j++)
     if(stricmp(s1[i].name[i],s1[j].name[j])>0)
      {
        strcpy(s.temp,s1[i].name[i]);
        strcpy(s1[i].name[i],s1[j].name[j]);
        strcpy(s1[j].name[j],s.temp);
       }
    }
   for(i=1;i<n;i++)
    {
      printf("\n%s",s1[i].name[i]);
     }
 printf("\n\t\t####3BRACES SEARCH####\n\t\t\t");
 scanf("%s",s.na);
 printf("\n\t\t SEARCH RESULTS");
 for(i=0;i<n;i++)
 {
   if(s.na[0]==s1[i].name[i][0])
   printf("\n\t\t%s",s1[i].name[i]);
 }
getche();
}

Output:
       Enter the names below
       NOTE:TYPE 0 WHEN FINISHED
       facebook
       apple
       zoo
       font
       lobby
       chennai
       newyork
       zoho
                                       ####3BRACES SEARCH####
                                                      f
                                       SEARCH RESULTS
                                       facebook
                                       font
                                            

1 comment: