neeraj goswami 0 Newbie Poster
//take mob.no  ,name ,bill amt
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct mob1
{
    char mob[10];
    char name[10];
    float bill;
};
int main()
{
     struct mob1 a[30]={{'\0'},{'\0'},0.0};
    void accept(struct mob1 a[30],int n);
    void display(struct mob1 a[30],int n);
    int append(struct mob1 a[30],int n);
    void selmob(struct mob1 a[30],int n);
    void srch(struct mob1 a[30],char [],int,int);
    void insmob(struct mob1 a[30],int n);
    int ch,n;
    char src[10];
    clrscr();

    do
    {
        printf("\n1...accept");
        printf("\n2...display");
        printf("\n3...append");
        printf("\n4...selection sort by mob no");
        printf("\n5..insertion sort name");
        printf("\n6...binary srch no");
        printf("\nenter the choice:");
        scanf("%d",&ch);
        printf("\n\n");
        switch(ch)
        {
            case 1:
                printf("\nenter no of entry:");
                scanf("%d",&n);
                accept(a,n);
                break;
            case 2:
                display(a,n);
                break;
            case 3:
                n=append(a,n);
                display(a,n);
                break;
            case 4:
                selmob(a,n);
                display(a,n);
                break;
            case 5:
                insmob(a,n);
                display(a,n);
                break;
            case 6:
                printf("\nenter the no for search");
                flushall();
                scanf("%s",src);
                srch(a,src,0,n-1);
                //display(a,n);
                break;
        }

    }while(ch<6&&ch>0);
    getch();
    return 0;
}
void accept(struct mob1 a[30],int n)
{
    int i;
    char mob[30];
    float bill1=0.0;
    for(i=0;i<n;i++)
    {
        /*printf("\nmob no=");
        flushall();
        scanf("%s",a[i].mob);*/
        printf("\nname=");
        flushall();
        scanf("%s",a[i].name);
        /*printf("\nbill no=");
        scanf("%f",&bill1);
        a[i].bill=bill1;*/
    }
}

void display(struct mob1 a[30],int n)
{
    int i;
    //float bill1=0.0;
       printf("mob\t\tname\t\tbill\n\n");
    for(i=0;i<n;i++)
    {
        printf("\n%s\t\t%s\t\t%f\n",a[i].mob,a[i].name,a[i].bill);
    }
}

int append(struct mob1 a[30],int n)
{
    int i;
    float bill1=0.0;
        printf("\nmob no=");
        flushall();
        scanf("%s",a[n].mob);
        printf("\nname=");
        flushall();
        scanf("%s",a[n].name);
        printf("\nbill no=");
        scanf("%f",&bill1);
        a[n].bill=bill1;

    n++;
    return n;
}
void selmob(struct mob1 a[30],int n)
{
    int i,j,min;
    char mo[20];
    struct mob1 temp;
    for(i=0;i<n;i++)
    {
        min=i;
        strcpy(mo,a[min].mob);
        for(j=i+1;j<n-1;j++)
        {
            if(strcmp(a[j].mob,mo)<0)
            {
                min=j;
            }
        }
        temp=a[min];
        a[min]=a[i];
        a[i]=temp;
           //   display(a,n);


        //display(a,n);
    }
}
void srch(struct mob1 a[30],char src[10],int low,int high)
{
    int i=0,mid=0;
    mid=(high+low)/2;
    if(strcmp(a[i].mob,src)==0)
    {

        if(strcmp(a[i].mob,a[mid].mob)==0)
        {
            //return p;
            printf("\n mob found\n");
            printf("name=%s\n",a[i].name);
            printf("bill=%f",a[i].bill);
        }

           else if(strcmp(a[i].mob,a[mid].mob)<0)
        {
              srch(a,src,low,mid-1);
        }
        else if(strcmp(a[i].mob,a[mid].mob)>0)
        {
              srch(a,src,mid+1,high);
        }
           }
        else
        printf("\nnot found");

}

void insmob(struct mob1 a[30],int n)
{

    int i,j,hold=0;
    for(i=1;i<n-1;i++)
    {
        hold=i;
        for(j=i-1;j>=0;j--)
        {

        if(strcmp(a[j].name,a[hold].name)<0)
        {
            a[j+1]=a[j];
            //strcpy(a[j+1].name,a[hold].name);
            //a[j+1].bill=a[hold].bill;
        }
        }
           //strcpy(a[j+1].name,a[j].name);
        //a[j+1].bill=a[j].bill;
        a[j+1]=a[hold];
    }
}