Click the mouse button and record stored in file using C


#include "stdio.h"  #include "conio.h"  #include "graphics.h"
#include "stdlib.h" #include "dos.h"  #include "string.h"
void main(){
    union REGS i,o;
    int gd=DETECT,gm,no,bu,x,y,j,l,c,r;
    char nm[50],ch[100],num,de[50],str[50];
    FILE *fp;    clrscr();
    initgraph(&gd,&gm,"c:\\tc\\bgi");
    do    {
        fp=fopen("123.txt","r");
        setcolor(BLACK);
       bar(10,10,50,30);
        outtextxy(15,15,"Add");
        bar(70,10,110,30);
        outtextxy(132,15,"Exit");
        r=4;        gotoxy(1,r);       
        while(!feof(fp))        {
            num=fgetc(fp);
            printf("%c",num);
           if(num=='\n')            {
                r=r+1;
           }        }
        i.x.ax=1;
        int86(0x33,&i,&o);
        start1:
        while(!kbhit())        {
            i.x.ax=3;
           int86(0x33,&i,&o);
            gotoxy(2,2);
            bu=o.x.bx&1;
            switch(bu)            {
                case 1 :
                    goto start2;
            }        }
        start2 :
        if(o.x.cx>=10 && o.x.cx<=50 && o.x.dx>=10 && o.x.dx<=30)        {
            fp=fopen("123.txt","a+");
            gotoxy(1,r+1);
            printf("Enter No=");
            scanf("%d",&no);
            gotoxy(1,r+2);
            printf("Enter Name=");
            scanf("%s",&nm);
            fprintf(fp,"%d %s\n",no,nm);
            gotoxy(1,r+4);
            printf("Record is Save Successfully");
            getch();
        }
        else if(o.x.cx>=130 && o.x.cx<=170 && o.x.dx>=10 && o.x.dx<=30)        {
            getch();            closegraph();            exit(1);
        }
        else        {
            goto start1;
       }
        gotoxy(1,25);
        printf("Do You Want To Continue Press y/Y=");
        scanf("%s",&num);
        cleardevice();        fclose(fp);
    }while(num=='Y' || num=='y');
    printf("Press Any Key To Exit");
    closegraph();
    fclose(fp);
    getch();
}