Showing posts with label Projects In C. Show all posts
Showing posts with label Projects In C. Show all posts

Railway Reservation System Project In C

Railway Reservation System Project In C


#include conio.h
#include stdio.h
#include graphics.h
#include stdlib.h
#include dos.h
#include string.h
#include math.h

/***************Global Variable Declarations****************/

union REGS i,o;
int xmax,ymax;
int gdriver = DETECT, gmode, errorcode,x,y;
int count=0,no_pass=0;
FILE *ptr1;
char d[8][3]={{"S1"},{"S2"},{"S3"},{"S4"},{"S5"},{"S6"},{"S7"},{"S8"}};
char x1[2];

/****************************Global Structures declared**********/

struct travel
{
char tno[5];
//char doj[10];
int d1,m1,y1;
char from[4];
char to[4];
char passen[6][20];
char sex[6][2];
char age[6][3];
int seat_no[6];
char coano[3];
   // float pnr;
long int pnr;
float bill;
}passenger;
struct
{
// float pnr;
long int pnr;
}pass;
struct
{
int seat_no;
char coano[3];
char status[1];
}berth;

struct
{
char tno[5];
char tname[20];
}train;


/***********************User Defined Functions***********/

void firstscreen();
void mainmenu();
void reserv();
void clear();
void setgraph();
void clearline();
void drawbox();
void cancel();
void enquiry();
void color(int,int,int);
void printtic(struct travel);

/*****************Main Function*****************************/
void main()
{
int i;
FILE *ptr,*tr;
/***********loop for writing train nos***************/
if((tr=fopen("tra.dat","r"))==NULL)
{
tr=fopen("tra.dat","w");
strcpy(train.tno,"3143");
strcpy(train.tname,"Darjeeling Mail");
fwrite(&train,sizeof(train),1,tr);
strcpy(train.tno,"3147");
strcpy(train.tname,"Uttarbanga Exp");
fwrite(&train,sizeof(train),1,tr);
fclose(tr);
}

/************loop for writing train berth nos*********/
if((ptr=fopen("berths3.dat","r"))==NULL)
{
   ptr=fopen("berths3.dat","wb");
   strcpy(berth.coano,d[0]);
   strcpy(berth.status,"V");
   for(i=1;i<=73;i++)
   {
  if(i>72)
  {
count++;
strcpy(berth.coano,d[count]);
i=1;
  }
  if(count==8)
  break;
  berth.seat_no=i;
  fwrite(&berth,sizeof(berth),1,ptr);

   }
}
fclose(ptr);
if((ptr=fopen("berths7.dat","r"))==NULL)
{
   ptr=fopen("berths7.dat","wb");
   strcpy(berth.coano,d[0]);
   strcpy(berth.status,"V");
   for(i=1;i<=73;i++)
   {
  if(i>72)
  {
count++;
strcpy(berth.coano,d[count]);
i=1;
  }
  if(count==8)
  break;
  berth.seat_no=i;
  fwrite(&berth,sizeof(berth),1,ptr);

   }
     }
     fclose(ptr);
textcolor(WHITE);
textbackground(BLACK);
clrscr();
firstscreen();
mainmenu();
reserv();
cancel();

getch();
}
void firstscreen()
{
int r,c;
for(r=4;r<=20;r++)
{
gotoxy(20,r);
printf("*");
gotoxy(60,r);
printf("*");
}
for(c=20;c<60;c++)
{
gotoxy(c,4);
printf("*");
gotoxy(c,20);
printf("*");
}

gotoxy(36,6);
textattr(LIGHTRED);
cprintf("PROJECT");

gotoxy(39,8);
textcolor(BLUE);
cprintf("ON");

gotoxy(32,10);
textcolor(BROWN);
cprintf("Railway Reservation");

gotoxy(25,13);
textcolor(YELLOW);
putch(1);

textcolor(CYAN);
cprintf(" DEVELOPERS : ");


gotoxy(25,17);
textcolor(YELLOW);
putch(2);

textcolor(CYAN);
cprintf("RRP");
textcolor(CYAN);
cprintf("popsys");
gotoxy(28,23); textcolor(MAGENTA + BLINK);
cprintf("Press a key to continue");
getch();
}

void mainmenu()
{
char choice;
setgraph();
settextjustify(CENTER_TEXT, CENTER_TEXT);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
outtextxy(xmax,45,"Railway Reservation");
/* draw a rectangle */
rectangle(100,150,500,350);
gotoxy(17,12);
printf("1. For reservation press  1
");
gotoxy(17,14);
printf("2. For cancellation press 2
");
gotoxy(17,16);
printf("3. For enquiry press 3
");
gotoxy(17,18);
printf("4. For closing the program press 4
");
gotoxy(48,25);
printf("Created by SOFTECH SOLUTIONS Ltd.");
gotoxy(20,20);
printf("Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
reserv();
break;
case 2:
closegraph();
clrscr();
cancel();
break;
case 3:
closegraph();
enquiry();
break;
case 4:
exit(1);
default:
gotoxy(29,20);
printf("Not a valid choice");
getch();
main();
}
}
int pass_name(int i,int x, int y)
{
int flag,pos;
do
{
flag=1;
gotoxy(x,y);
fflush(stdin);
gets(passenger.passen[i]);
fflush(stdin);
strupr(passenger.passen[i]);
if (strlen(passenger.passen[i]) == 0)
{
if(i>0)
{
return(7);
}
gotoxy(10,24);
printf("aPassenger Name should not be left BLANK");
flag=0;
//i--;
getch();
clearline(24);
}
else if (strlen(passenger.passen[i]) >20)
{
//gotoxy(10,20);
gotoxy(10,24);
printf("aPassenger Name must be less than 20 characters");
flag=0;
getch();
clearline(24);
}
}while(flag==0);
gotoxy(x,y);
puts(passenger.passen[i]);
i++;
return(i);
}
int pass_sex(int j,int x,int y)
{
int flag,i;
char ch[1][1];
do
{
flag=1;
gotoxy(x,y);
fflush(stdin);
gets(passenger.sex[j]);
fflush(stdin);
strupr(passenger.sex[j]);
if (strlen(passenger.sex[j]) == 0)
{
gotoxy(10,24);
printf("aSex should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if(strlen(passenger.sex[j])!=1)
{
gotoxy(10,24);
printf("aPassenger's Sex must be 1 characters long");
flag=0;
getch();
clearline(24);
}
}while (flag==0);
gotoxy(x,y);
puts(passenger.sex[j]);
j++;
return(j);
}

int pass_age(int k,int x,int y)
{
int flag,i,j;
do
{
flag=1;
gotoxy(x,y);
if(flag==1)
no_pass++;
gets(passenger.age[k]);
fflush(stdin);
strupr(passenger.age[k]);
if (strlen(passenger.age[k]) == 0)
{
gotoxy(10,24);
printf("aPassenger's Age should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if (strlen(passenger.age[k])!=2)
{
gotoxy(10,24);
printf("aPassenger's Age must be equal to 2 characters");
flag=0;
// k--;
getch();
clearline(24);
}
else if(strcmp(passenger.age[k],"00")==0)
{
gotoxy(10,24);
printf("aPassenger's Age cannot be less than 1 year");
flag=0;
getch();
clearline(24);
}
for(i=k;i
{
for(j=0;j<2;j++)
{
if(!isdigit(passenger.age[i][j]))
{
gotoxy(10,24);
printf("aEnter a valid age");
flag=0;
getch();
clearline(24);
}
}
}
}while (flag==0);
gotoxy(x,y);
k++;
puts(passenger.age[k]);
return(k);
}

showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
int restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);

i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}

void clear()
{
int i,j;
for(i=0;i<=80;i++)
{
for(j=0;j<=25;j++)
{
printf("%c",' ');
gotoxy(i,j);
}
}
gotoxy(1,1);
}
void setgraph()
{

clrscr();

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\tc\bgi");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
  printf("Graphics error: %s
", grapherrormsg(errorcode));
  printf("Press any key to halt:");
  getch();
  exit(1);
}

xmax = getmaxx()/2;
ymax = getmaxy()/2;
}
void clearline(int yco)
{
int i,j;
gotoxy(5,yco);
for(i=0;i<70;i++)
{
printf("%c",' ');
}
}
void drawbox()
{
int xr,xc;
int la,ra;
gotoxy(0,0);
for(xr=1;xr<=80;xr++)
printf("Ä");
xc=2;
for(la=1;la<=23;la++)
{
gotoxy(1,xc);
printf("³");
gotoxy(80,xc);
printf("³");
xc++;
}
gotoxy(0,25);
for(xr=1;xr<80;xr++)
printf("Ä");
gotoxy(1,1);
printf("Ú");
gotoxy(80,24);
printf("³");
}


void reserv()
{
int i,flag,j,k,test,found,set_no,count1=0,year;
struct date d;
float pnrno;
char tno[3],ans;
char a[1],c,age[3],ch;
char *p;
FILE *ptr,*pno,*tr;
closegraph();
highvideo();
//Design Part
clear();
drawbox();
gotoxy(3,2);
for(i=0;i<74;i++)
printf("Ä");

j=3;
for(i=0;i<4;i++)
{
gotoxy(3,j);
printf("³");

gotoxy(77,j);
printf("³");
j++;
}
gotoxy(3,6);
for(i=0;i<75;i++)
printf("Ä");
gotoxy(6,2);
printf(" Journey Details ");
color(15,18,3);
gotoxy(5,3);
printf("Train No : ");
color(32,46,3);
gotoxy(20,3);
printf("Train Name :");
color(67,68,3);
color(71,72,3);
color(75,76,3);
gotoxy(49,3);
printf("Date of Booking :");
gotoxy(67,3);
getdate(&d);
printf("%d",d.da_day);
gotoxy(69,3);
putch('-');
gotoxy(71,3);
printf("%d",d.da_mon);
putch(' -');
printf("%d",d.da_year);
color(12,14,5);
gotoxy(5,5);
printf("From :");
color(27,29,5);
gotoxy(20,5);
printf("To :");
color(67,68,5);
color(71,72,5);
color(75,76,5);
gotoxy(49,5);
printf("Date Of Journey :");
gotoxy(3,8);
for(i=0;i<=74;i++)
printf("Ä");
gotoxy(7,8);
printf("Passenger Details");
j=9;
for(i=0;i<14;i++)
{
gotoxy(3,j);
printf("³");

gotoxy(77,j);
printf("³");
j++;
}
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
for(i=0;i<74;i++)
printf("Ä");
gotoxy(4,10);
for(i=0;i<73;i++)
printf("Ä");
color(8,31,11);
gotoxy(22,9);
printf("NAME");

gotoxy(46,9);
printf("SEX");
gotoxy(53,9);
printf("AGE");
gotoxy(65,9);
printf("REMARKS");
j=9;
for(i=0;i<14;i++)
{
gotoxy(44,j);
printf("³");

gotoxy(51,j);
printf("³");

gotoxy(58,j);
printf("³");
j++;
}

for(i=0;i<6;i++)
{
color(5,38,(11+i));
color(46,48,(11+i));
color(53,56,(11+i));
color(5,38,(16+i));
color(46,48,(16+i));
color(53,56,(16+i));
}

//User input part
gotoxy(15,3);
do
{
int len;
fflush(stdin);
//name input
gets(passenger.tno);
if(len=(strlen(passenger.tno))!=4)
{
gotoxy(10,24);
printf("Train No Must be 4 digits long");
getch();
clearline(24); //clears the line
gotoxy(15,3);
}
tr=fopen("tra.dat","r");
fread(&train,sizeof(train),1,tr);
while(!feof(tr))
{
if((strcmp(passenger.tno,train.tno))==0)
{
found=0;
flag=0;
break;
}
else
found=2;
fread(&train,sizeof(train),1,tr);
}
if(found==2)
{
gotoxy(8,24);
printf("This Train No does not exist");
getch();
clearline(24);
gotoxy(15,3);
flag=1;
}
}while(strlen(passenger.tno)!=4||flag==1);
if(found==0)
{
gotoxy(32,3);
puts(train.tname);
found=1;
}

fflush(stdin);
do
{
flag=1;
gotoxy(12,5);
fflush(stdin);
scanf("%[^
]",passenger.from);
fflush(stdin);
strupr(passenger.from);
if (strlen(passenger.from) == 0)
{
gotoxy(10,24);
printf("aFrom field should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if (strlen(passenger.from) != 3)
{
gotoxy(10,24);
printf("aFrom should be equal to 3 characters");
flag=0;
getch();
clearline(24);
}
for(i=0;i<3;i++)
{
ch=passenger.from[i];
if(isdigit(ch))
{
gotoxy(10,24);
printf("aEnter a valid Boarding Place");
flag=0;
getch();
clearline(24);
break;
}
}
}while (flag==0);
gotoxy(12,5);
puts(passenger.from);

do
{
flag=1;
gotoxy(27,5);
fflush(stdin);
scanf("%[^
]",passenger.to);
fflush(stdin);
strupr(passenger.to);
if (strlen(passenger.to) == 0)
{
gotoxy(10,24);
printf("aTo field should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if (strlen(passenger.to) != 3)
{
gotoxy(10,24);
printf("aTo should be equal to 3 characters");
flag=0;
getch();
clearline(24);
}
for(i=0;i<3;i++)
{
ch=passenger.to[i];
if(isdigit(ch))
{
gotoxy(10,24);
printf("aEnter a valid Destination Place");
flag=0;
getch();
clearline(24);
break;
}
}
}while (flag==0);
gotoxy(27,5);
puts(passenger.to);
i=j=k=0;

gotoxy(67,5);
while(c!=13)
{
   fflush(stdin);
   c=getch();
   if((c<'0'||c>'9')&&c!=13&&c!=8)
   {
if(c==27)
 return;
gotoxy(5,24);
printf("Please Enter Valid Date.");
getch();
gotoxy(67,5);
printf("  ");
gotoxy(5,24);
clearline(24);
gotoxy(67,5);
count1=0;
c='a';
   }
   else if(c==8)
   {
  if(wherex()>69)
  {
 gotoxy(wherex()-1,15);
 putch(' ');
 count1--;
 gotoxy(wherex()-1,15);
  }
   }
   else if(c!=13)
   {
  if(wherex()<69)
  {
 putch(c);
 age[count1]=c;
 count1++;
  }
  else
  {
 gotoxy(5,24);
 printf("Date Can Be Only 2 Digits.");
 getch();
 clearline(24);
 gotoxy(67,5);
  }
   }
else
{
age[count1]='



Related Links :

C Program to create a calendar for DOS

 


#include
#include
#include "scaldate.h"

/*
** calendar generation information
*/

int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char *daynames[8] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

/*
** box drawing stuff
*/

#if defined(MSDOS) || defined(_WIN32)
const char *topborder = "\xd5\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xb8";
const char *midborder = "\xc6\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xb5";
const char *botborder = "\xd4\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xbe";
const char *line = "\xb3";
#else
const char *line = "";
#endif

/*
** tell 'em they messed up
*/

void usage(void)
{
puts("Usage: CAL [m y]");
puts("where: m = month (1 - 12)");
puts(" y = year (1 - 99, 1800 - 3000)");
exit(-1);
}

/*
** here's where the real work's done
*/

int main(int argc, char *argv[])
{
int day, day_1, numdays, i, j;
unsigned yr, mo;

if (argc < 3 && argc > 1)
usage();

if (argc >= 3)
{
yr = atoi(argv[2]);
mo = atoi(argv[1]);
}
else
{
long dnow = today();
unsigned dy;

scalar_to_ymd(dnow, &yr, &mo, &dy);
}

if (!mo || 12 < mo)
usage();

if (100 > yr)
yr += 1900;

if (3000 < yr || 1800 > yr)
usage();

for (i = 0, mo -= 1; i < 3; ++i, ++mo)
{
if (!mo)
{
mo = 12;
--yr;
}
if (12 < mo)
{
mo = 1;
++yr;
}
numdays = days[mo - 1];
if (2 == mo && isleap(yr))
++numdays;
day_1 = (int)((ymd_to_scalar(yr, mo, 1) - (long)ISO_CAL) % 7L);

#if defined(MSDOS) || defined(_WIN32)
if (!i)
puts(topborder);
#endif
fputs(line, stdout);
for (j = 0; j < 7; )
{
fputs(daynames[ISO_CAL + j], stdout);
if (7 != ++j)
fputc(' ', stdout);
}
printf("%s < %s, %d\n%s", line, month[mo - 1], yr, line);

for (day = 0; day < day_1; ++day)
fputs(" ", stdout);
for (day = 1; day <= numdays; ++day, ++day_1, day_1 %= 7)
{
if (!day_1 && 1 != day)
printf("\b%s\n%s", line, line);
printf("%3d ", day);
}
for ( ; day_1; ++day_1, day_1 %= 7)
fputs(" ", stdout);
#if defined(MSDOS) || defined(_WIN32)
printf("\b%s\n", line);
if (2 > i)
puts(midborder);
else puts(botborder);
#else
fputc('\n', stdout);
#endif
}
return 0;
}



Related Links :

C Project to create a Notepad Editor Utility With Menu Bar In C



#include
#include
#include
#include
#include
#include
char far *vid=0xB8000000;
char a[50000],*str;
int track[2000],fp=1,lp=21,cl=1,p=0,t=0,eat;

/*This function writes a character into video memory.*/
writechar(char ch,int attr,int row,int col)
{
char far *v;
v=vid+row*160+col*2;
*v=ch;
v++;
*v=attr;
}/*End wrotechar*/
//-----------------------------------------------------------------------

/*This function draws a box of given attribute & size*/
drawbox(int r1,int c1,int r2,int c2,int attr)
{ int i,j;
for(i=r1;i<=r2;i++)
{ for(j=c1;j<=c2;j++)
writechar(' ',attr,i,j);
}
}/*End drawbox*/
//------------------------------------------------------------------------

/*This function draws the screen at starting*/
drawscreen()
{ drawbox(0,0,0,79,120);
drawbox(24,0,24,79,120);
drawbox(1,0,23,79,16);
doubleborder(1,0,23,79,31);
}/*End drawscreen*/
//------------------------------------------------------------------------

/*This function refreshes the screen*/
refreshscreen()
{ int r,c;
drawbox(2,1,22,78,16);

}/*End Refreshscreen*/
//-------------------------------------------------------------------------

/*This function draws the double border*/
doubleborder(int r1,int c1,int r2,int c2,int attr)
{ int r,c;
writechar(201,attr,r1,c1);
writechar(187,attr,r1,c2);
writechar(200,attr,r2,c1);
writechar(188,attr,r2,c2);


for(c=(c1+1);c<=(c2-1);c++)
writechar(205,attr,r1,c);

for(c=(c1+1);c<=(c2-1);c++)
writechar(205,attr,r2,c);

for(r=(r1+1);r<=(r2-1);r++)
writechar(186,attr,r,c1);

for(r=(r1+1);r<=(r2-1);r++)
writechar(186,attr,r,c2);

}/*End doubleborder*/
//---------------------------------------------------------------------------

/*This function draws border of given attribute & size*/
drawborder(int r1,int c1,int r2,int c2,int attr)
{ int r,c;

writechar(218,attr,r1,c1);
writechar(191,attr,r1,c2);
writechar(192,attr,r2,c1);
writechar(217,attr,r2,c2);

r=r1;
for(c=c1+1;c<=c2-1;c++)
writechar(196,attr,r,c);

r=r2;
for(c=c1+1;c<=c2-1;c++)
writechar(196,attr,r,c);

c=c1;
for(r=r1+1;r<=r2-1;r++)
writechar(179,attr,r,c);

c=c2;
for(r=r1+1;r<=r2-1;r++)
writechar(179,attr,r,c);

}/*End drawborder*/
//---------------------------------------------------------------------------

/*This function draws a line of given attribute*/
drawline(int r,int c1,int c2,int attr)
{ int i;
writechar(195,attr,r,c1);
writechar(180,attr,r,c2);
for(i=c1+1;i<=c2-1;i++)
writechar(196,attr,r,i);
}/*End drawline*/
//---------------------------------------------------------------------------

/*This function writes a string in given row & column with given attribute*/
writestring(char *p,int attr,int r,int c)
{ int l,i;
l=strlen(p);
for(i=0;i<=l;i++)
{ writechar(*(p+i),attr,r,c);
c++;
}
}/*End writestring*/
//---------------------------------------------------------------------------

/*This function saves the content of videomemory from r1,c1 to r2,c2
into main memory using char buffer*/
char *savemem(int r1,int c1,int r2,int c2,char *buff)
{ char far *v;
int i,j,k=0,size;

size=(r2-r1+1)*(c2-c1+1)*2;
buff=(char *)malloc(size);

for(i=r1;i<=r2;i++)
{ for(j=c1;j<=c2;j++)
{ v=(vid+i*160+j*2);
*(buff+k)=*v;
k++;
v++;
*(buff+k)=*v;
k++;
}
}
return(buff);
}/*End savememo*/
//---------------------------------------------------------------------------

/*This function restores the content of main memory into videomemory
from r1,c1 to r2,c2 using char buffer*/
restoremem(int r1,int c1,int r2,int c2,char *buff)
{ char far *v;
int i,j,k=0;


for(i=r1;i<=r2;i++)
{ for(j=c1;j<=c2;j++)
{ v=(vid+i*160+j*2);
*v=*(buff+k);
k++;
v++;
*v=*(buff+k);
k++;

}
}
free(buff);
}/*End restorememory*/
//---------------------------------------------------------------------------
savefile()
{ FILE *fp;
int i,j;
//char *str="c:\\tc\\ex1";
fp=fopen(str,"w");
if(fp==NULL)
{ return;
}
i=0;
j=track[0];
while(j= { fputc(a[j],fp);
j++;
if(j==track[i+1])
{ fputc('\n',fp);
i++;
}
}

fputc('\n',fp);
fclose(fp);
}
//------------------------------------------------------------------------
saveasfile()
{ FILE *fp;
int i,j,r1,c1;
char *buff;
buff=savemem(8,18,16,58,buff);
drawbox(8,18,16,58,120);
doubleborder(8,18,16,58,127);
drawbox(10,21,10,55,16);
setcuserpos(10,21);

gets(str);
restoremem(8,18,16,58,buff);

fp=fopen(str,"w");
if(fp==NULL)
{ return;
}
i=0;
j=0;
while(j= { fputc(a[j],fp);
j++;
if(j==track[i+1])
{ fputc('\n',fp);
i++;
}
}

fputc('\n',fp);
fclose(fp);

}
//------------------------------------------------------------------------
openfile()
{ FILE *fp;
int i,j,r1,c1;
char *buff,ch;
buff=savemem(8,18,16,58,buff);
drawbox(8,18,16,58,120);
doubleborder(8,18,16,58,127);
drawbox(10,21,10,55,16);
setcuserpos(10,21);

gets(str);
restoremem(8,18,16,58,buff);
//writestring(str,31,1,30);
fp=fopen(str,"r");
p=0;
t=0;
track[0]=0;
while(!feof(fp))
{ ch=fgetc(fp);
if(ch!='\n')
{ a[p]=ch;
p++;
}
else
{ track[t+1]=p;
t++;
}
}
fclose(fp);
fp=1;
lp=21;
cl=1;
display();
}
//------------------------------------------------------------------------
/*This function opens the filemenu*/
int Filemenu(char *buff)
{ int i,sc,ac,c,r,r1,c1,flag;
char *s[]={"New","Open","Save","Save as","Close","Print","Exit"};
char *s1[]={"Create a new file",
"Load an existing file from the disk",
"Save current file",
"Save current file with new name",
"Close current file",
"Prints currently loaded file to printer",
"Exit the editor"
};
union REGS inregs,outregs;

setcursersize(32,10); /*Hides the curser*/
buff=savemem(1,1,12,20,buff);
drawbox(1,1,11,18,120);
drawbox(2,19,12,20,7);
drawbox(12,3,12,18,7);
drawborder(1,2,11,17,112);

r=2; c=4;
for(i=0;i=<7;i++)
{ writestring(s[i],112,r,c);
r++;
if(i==4)
{ drawline(r,2,17,112);
r++;
}
if(i==5)
{ drawline(r,2,17,112);
r++;
}
}


sc=72; flag=2;
while(1)
{ if(sc==72) /*Up arrow*/
{ if(flag==1)
flag=7;
else
flag--;
}
else /*Down arrow*/
{ if(sc==80)
{ if(flag==7)
flag=1;
else
flag++;
}
else
flag=8; /*Right or Left arrow*/
}
switch(flag)
{ case 1:
drawbox(2,3,2,16,32);
writestring(s[0],32,2,4);
r=2; i=0;
writestring(s1[0],112,24,1);
break;

case 2:
drawbox(3,3,3,16,32);
writestring(s[1],32,3,4);
r=3; i=1;
writestring(s1[1],112,24,1);
break;
case 3:
drawbox(4,3,4,16,32);
writestring(s[2],32,4,4);
r=4; i=2;
writestring(s1[2],112,24,1);
break;
case 4:
drawbox(5,3,5,16,32);
writestring(s[3],32,5,4);
r=5; i=3;
writestring(s1[3],112,24,1);
break;
case 5:
drawbox(6,3,6,16,32);
writestring(s[4],32,6,4);
r=6; i=4;
writestring(s1[4],112,24,1);
break;
case 6:
drawbox(8,3,8,16,32);
writestring(s[5],32,8,4);
r=8; i=5;
writestring(s1[5],112,24,1);
break;
case 7:
drawbox(10,3,10,16,32);
writestring(s[6],32,10,4);
r=10; i=6;
writestring(s1[6],112,24,1);
break;
case 8:
if(sc==77) /*Right arrow return */
{ restoremem(1,1,12,20,buff); /*Scancode of Editmenu*/
return(18);
}
else
{ if(sc==75)
{ restoremem(1,1,12,20,buff); /*Left arrow return*/
/*Scancode of Helpmenu*/
return(35);
}
else
{ restoremem(1,1,12,20,buff);/*Return & Escape*/
return(sc);
}
}
}
getcharacter(&sc,&ac);

drawbox(r,3,r,16,112);
writestring(s[i],112,r,4);
drawbox(24,1,24,55,112);
if(ac==13)
{ switch(r)
{ case 2: restoremem(1,1,12,20,buff);
refreshscreen();
setcuserpos(2,1);
fp=1;
cl=1;
t=0;
lp=21;
p=0;
return(1);
case 3: readcurser(&r1,&c1);
restoremem(1,1,12,20,buff);
openfile();
setcuserpos(r1,c1);
return(1);

case 4: readcurser(&r1,&c1);
restoremem(1,1,12,20,buff);
savefile();
setcuserpos(r1,c1);
return(1);

case 5: readcurser(&r1,&c1);
restoremem(1,1,12,20,buff);
saveasfile();
setcuserpos(r1,c1);
return(1);
case 6:
case 8:
case 10:
return(0);
} }


}
}/*End filemenu*/
//-------------------------------------------------------------------------

/*This function opens the Editmenu*/
int Editmenu(char *buff)
{ int i,sc,ac,r,c,flag;
char *s[]={"Cut Ctrl+X","Copy Ctrl+C","Paste Ctrl+V","Clear Del"};
char *s1[]={"Delete selected text and copies it to buffer",
"Copies selected text to buffer",
"Insert buffer contents at current location",
"Delete selected text without copying it to buffer"
};
union REGS inregs,outregs;

setcursersize(32,10); /*Hide the cursor*/
buff=savemem(1,8,7,28,buff);
drawbox(1,8,6,26,120);
drawbox(2,27,7,28,7);
drawbox(7,10,7,26,7);
drawborder(1,9,6,25,112);

r=2; c=11;
for(i=0;i<4;i++)
{ writestring(s[i],112,r,c);
r++;
}

sc=72; flag=2;
while(1)
{ if(sc==72) /*Up arrow*/
{ if(flag==1)
flag=4;
else
flag--;
}
else
{ if(sc==80) /*Down arrow*/
{ if(flag==4)
flag=1;
else
flag++;
}
else
flag=5; /*Right or Left arrow*/
}
switch(flag)
{ case 1:
drawbox(2,10,2,24,32);
writestring(s[0],32,2,11);
r=2; i=0;
writestring(s1[0],112,24,1);
break;

case 2:
drawbox(3,10,3,24,32);
writestring(s[1],32,3,11);
r=3; i=1;
writestring(s1[1],112,24,1);
break;
case 3:
drawbox(4,10,4,24,32);
writestring(s[2],32,4,11);
r=4; i=2;
writestring(s1[2],112,24,1);
break;
case 4:
drawbox(5,10,5,24,32);
writestring(s[3],32,5,11);
r=5; i=3;
writestring(s1[3],112,24,1);
break;
case 5:
if(sc==77) /*Right arrow return */
{ restoremem(1,8,7,28,buff); /*Scancode of Searchmenu*/
return(31);
}
else
{ if(sc==75)
{ restoremem(1,8,7,28,buff);/*Left arrow return */
return(33); /*Scancode of Filemenu*/
}
else
{ restoremem(1,8,7,28,buff);
return(sc); /*Return & Escape*/
}
}
}
getcharacter(&sc,&ac);

drawbox(r,10,r,24,112);
writestring(s[i],112,r,11);
drawbox(24,1,24,55,112);
}

}/*End Editmenu*/
//------------------------------------------------------------------------

/*This function opens the Searchmenu*/
int Searchmenu(char *buff)
{ int i,sc,ac,r,c,flag;
char *s[]={ "Find",
"Repeat Last Find F3",
"Replace"
};
char *s1[]={"Find specified text",
"Find next occurence of text specified in previous search",
"Finds and changes specified text"
};
union REGS inregs,outregs;

setcursersize(32,10); /*Hide the cursor*/
buff=savemem(1,14,6,44,buff);
drawbox(1,14,5,42,120);
drawbox(2,43,6,44,7);
drawbox(6,16,6,42,7);
drawborder(1,15,5,41,112);

r=2; c=17;
for(i=0;i<3;i++)
{ writestring(s[i],112,r,c);
r++;
}

sc=72; flag=2;
while(1)
{ if(sc==72) /*Up arrow*/
{ if(flag==1)
flag=3;
else
flag--;
}
else
{ if(sc==80) /*Down arrow*/
{ if(flag==3)
flag=1;
else
flag++;
}
else
flag=4; /*Right or Left arrow*/
}
switch(flag)
{ case 1:
drawbox(2,16,2,40,32);
writestring(s[0],32,2,17);
r=2; i=0;
writestring(s1[0],112,24,1);
break;

case 2:
drawbox(3,16,3,40,32);
writestring(s[1],32,3,17);
r=3; i=1;
writestring(s1[1],112,24,1);
break;
case 3:
drawbox(4,16,4,40,32);
writestring(s[2],32,4,17);
r=4; i=2;
writestring(s1[2],112,24,1);
break;
case 4:
if(sc==77)
{ restoremem(1,14,6,44,buff); /*Right arrow return*/
return(47); /*Scancode of Viewmenu*/
}
else
{ if(sc==75)
{ restoremem(1,14,6,44,buff);/*Left arrow return*/
return(18); /*Scancode of Editmenu*/
}
else
{ restoremem(1,14,6,44,buff);
return(sc); /*Return & Escape*/
}
}
}
getcharacter(&sc,&ac);

drawbox(r,16,r,40,112);
writestring(s[i],112,r,17);
drawbox(24,1,24,56,112);
}

}/*End Searchmenu*/
//------------------------------------------------------------------------

/*This function opens the Viewmenu*/
int Viewmenu(char *buff)
{ int i,sc,ac,r,c,flag;
char *s[]={ "Split Window Ctrl+F6",
"Size Window Ctrl+F8",
"Close Window Ctrl+F4",
"1 UNTITLED Alt+1"
};
char *s1[]={"Open a second edit window",
"Resize the edit window",
"Close the second edit window",
"Selects a file to view"
};
union REGS inregs,outregs;

setcursersize(32,10); /*Hide the cursor*/
buff=savemem(1,22,8,47,buff);
drawbox(1,22,7,45,120);
drawbox(2,46,8,47,7);
drawbox(8,24,8,45,7);
drawborder(1,23,7,44,112);

r=2; c=24;
for(i=0;i<4;i++)
{ writestring(s[i],112,r,c);
r++;
if(i==2)
{ drawline(r,23,44,112);
r++;
}
}

sc=72; flag=2;
while(1)
{ if(sc==72) /*Up arrow*/
{ if(flag==1)
flag=4;
else
flag--;
}
else
{ if(sc==80) /*Down arrow*/
{ if(flag==4)
flag=1;
else
flag++;
}
else
flag=5; /*Right or Left arrow*/
}
switch(flag)
{ case 1:
drawbox(2,24,2,43,32);
writestring(s[0],32,2,24);
r=2; i=0;
writestring(s1[0],112,24,1);
break;

case 2:
drawbox(3,24,3,43,32);
writestring(s[1],32,3,24);
r=3; i=1;
writestring(s1[1],112,24,1);
break;
case 3:
drawbox(4,24,4,43,32);
writestring(s[2],32,4,24);
r=4; i=2;
writestring(s1[2],112,24,1);
break;
case 4:
drawbox(6,24,6,43,32);
writestring(s[3],32,6,24);
r=6; i=3;
writestring(s1[3],112,24,1);
break;
case 5:
if(sc==77)
{ restoremem(1,22,8,47,buff); /*Right arrow return*/
return(24); /*Scancode of Optionmenu*/
}
else
{ if(sc==75)
{ restoremem(1,22,8,47,buff); /*Left arrow return*/
return(31); /*Scancode of Searchmenu*/
}
else
{ restoremem(1,22,8,47,buff);
return(sc); /*Return & Escape*/
}
}
}
getcharacter(&sc,&ac);

drawbox(r,24,r,43,112);
writestring(s[i],112,r,24);
drawbox(24,1,24,55,112);
}


}/*End Viewmenu*/
//-----------------------------------------------------------------------

/*This function opens the Optionmenu*/
int Optionmenu(char *buff)
{ int i,sc,ac,r,c,flag;
char *s[]={"Settings","About"};
char *s1[]={"Change editor setting",
"Change editor screen color"
};
union REGS inregs,outregs;

setcursersize(32,10); /*Hide the cursor*/
buff=savemem(1,28,5,46,buff);
drawbox(1,28,4,44,120);
drawbox(2,45,5,46,7);
drawbox(5,30,5,44,7);
drawborder(1,29,4,43,112);

r=2; c=31;
for(i=0;i<2;i++)
{ writestring(s[i],112,r,31);
r++;
}

sc=72; flag=2;
while(1)
{ if(sc==72) /*Up arrow*/
{ if(flag==1)
flag=2;
else
flag--;
}
else
{ if(sc==80) /*Down arrow*/
{ if(flag==2)
flag=1;
else
flag++;
}
else
flag=3; /*Right or Left arrow*/
}
switch(flag)
{ case 1:
drawbox(2,30,2,42,32);
writestring(s[0],32,2,31);
r=2; i=0;
writestring(s1[0],112,24,1);
break;

case 2:
drawbox(3,30,3,42,32);
writestring(s[1],32,3,31);
r=3; i=1;
writestring(s1[1],112,24,1);
break;
case 3:
if(sc==77)
{ restoremem(1,28,5,46,buff); /*Right arrow return*/
return(35); /*Scancode of Helpmenu*/
}
else
{ if(sc==75)
{ restoremem(1,28,5,46,buff);/*Left arrow return*/
return(47); /*Scancode of Viewmenu*/
}
else
{ restoremem(1,28,5,46,buff);
return(sc); /*Return & Escape*/
}
}
}
getcharacter(&sc,&ac);

drawbox(r,30,r,42,112);
writestring(s[i],112,r,31);
drawbox(24,1,24,55,112);
}

}/*End Optionmenu*/
//------------------------------------------------------------------------

/*This function opens the Helpmenu*/
int Helpmenu(char *buff)
{ int i,sc,ac,r,c,flag;
char *s[]={"Commands","About"};
char *s1[]={"Help on edit commands",
"About help"
};
union REGS inregs,outregs;

setcursersize(32,10); /*Hide the cursor*/
buff=savemem(1,36,5,52,buff);
drawbox(1,36,4,50,120);
drawbox(1,51,5,52,7);
drawbox(5,36,5,50,7);
drawborder(1,37,4,49,112);

r=2; c=39;
for(i=0;i<2;i++)
{ writestring(s[i],112,r,c);
r++;
}

sc=72; flag=2;
while(1)
{ if(sc==72) /*Up arrow*/
{ if(flag==1)
flag=2;
else
flag--;
}
else
{ if(sc==80) /*Down arrow*/
{ if(flag==2)
flag=1;
else
flag++;
}
else
flag=3; /*Right or left arrow*/
}
switch(flag)
{ case 1:
drawbox(2,38,2,48,32);
writestring(s[0],32,2,39);
r=2; i=0;
writestring(s1[0],112,24,1);
break;

case 2:
drawbox(3,38,3,48,32);
writestring(s[1],32,3,39);
r=3; i=1;
writestring(s1[1],112,24,1);
break;
case 3:
if(sc==77)
{ restoremem(1,36,5,52,buff);/*Right arrow return*/
return(33); /*Scancode of Filemenu*/
}
else
{ if(sc==75)
{ restoremem(1,36,5,52,buff);/*Left arrow return*/
return(24); /*Scancode of Optionmenu*/
}
else
{ restoremem(1,36,5,52,buff);
return(sc); /*Return & Escape*/
}
}
}

getcharacter(&sc,&ac);

drawbox(r,38,r,48,112);
writestring(s[i],112,r,39);
drawbox(24,1,24,55,112);
}


}/*End Helpmenu*/
//-----------------------------------------------------------------------

/*This function is used to hides the curser*/
setcursersize(int x,int y)
{ union REGS inregs,outregs;
inregs.h.ah=0x01;
inregs.h.ch=x;
inregs.h.cl=y;
int86(0x10,&inregs,&outregs);
}/*End setcurser*/
//------------------------------------------------------------------------

/*This function sets the cursor at given position*/
setcuserpos(int a,int b)
{ union REGS inregs,outregs;
inregs.h.ah=0x02;
inregs.h.bh=0;
inregs.h.dh=a;
inregs.h.dl=b;
int86(0x10,&inregs,&outregs);
}/*End setcurserpos*/
//-------------------------------------------------------------------------

/*This function is used to read current position of curser*/
readcurser(int *p1,int *p2)
{
union REGS inregs,outregs;
inregs.h.ah=0x03;
inregs.h.bh=0;
int86(0x10,&inregs,&outregs);
*p1=outregs.h.dh;
*p2=outregs.h.dl;
}/*End readcurser*/
//------------------------------------------------------------------------

getcharacter(int *p1,int *p2)
{ union REGS inregs,outregs;
inregs.h.ah=0;
int86(0x16,&inregs,&outregs);
*p1=outregs.h.ah;
*p2=outregs.h.al;
}
//------------------------------------------------------------------------

display()
{ int i,j,c=1,k=2,m;

refreshscreen();
for(i=fp-1;i<=t;i++)
{ if(i==lp)
break;
for(j=track[i]+eat; j { if(j>=track[i+1] && i!=t)
break;
if(a[j]==9)
{ for(m=0;m<8;m++)
writechar(32,23,k,c);
}
else
{
writechar(a[j],23,k,c);
}
c++;
}
c=1;
k++;
}
}
//-------------------------------------------------------------------------
delete1(int temp)
{ int i;
memmove(a+temp,a+(temp+1),1000-(temp+1));
p--;
for(i=cl;i<=t;i++)
track[i]=track[i]-1;
display();
}
//------------------------------------------------------------------------
insert(int temp,int ac)
{ int i;
memmove(a+(temp+1),a+temp,1000-temp);
p++;
*(a+temp)=ac;
for(i=cl;i<=t;i++)
track[i]=track[i]+1;
}
//-------------------------------------------------------------------------
activescreen(int sc,int ac,int *r,int *c)
{ int r1,c1,k,temp,i;
readcurser(&r1,&c1);

switch(sc)
{ case 71: if(eat!=0)
{ eat=0;
display();
}
readcurser(&r1,&c1);
c1=1;
setcuserpos(r1,c1);
break;

case 79: if(t!=(cl-1))
{ readcurser(&r1,&c1);
c1=track[cl]-track[cl-1]+1;
if(c1<78)
{ if(eat!=0)
{ eat=0;
display();
}
setcuserpos(r1,c1);
}
else
{ eat=c1-78;
display();
readcurser(&r1,&c1);
c1=78;
setcuserpos(r1,c1);
}
}
else
{ readcurser(&r1,&c1);
c1=p-track[cl-1]+1;
if(c1<78)
setcuserpos(r1,c1);
else
{ eat=c1-78;
display();
readcurser(&r1,&c1);
c1=78;
setcuserpos(r1,c1);
}
}
break;

case 73: if(fp!=1)
{ if(lp>41)
{ fp=fp-20;
lp=lp-20;
cl=cl-20;
display();
}
else
{ fp=1;
lp=21;
display();
readcurser(&r1,&c1);
cl=r1-1;
}
}
break;

case 81: if((fp+20) { fp=fp+20;
lp=lp+20;
cl=cl+20;
display();
if((lp-1)>t)
{ cl=t+1;
readcurser(&r1,&c1);
r1=cl-fp+2;
setcuserpos(r1,c1);
}
}
break;
case 83: if((cl-1)==t || (track[cl-1]+(c1+eat))<=track[cl])
{ readcurser(&r1,&c1);
temp=track[cl-1]+(c1+eat)-1;
delete1(temp);
}
else
{ temp=track[cl-1]+(c1+eat)-track[cl]-1;
k=temp+track[cl];
for(i=track[cl];i insert(i,32);

memmove(track+cl,track+(cl+1),99-(cl+1));
t--;
display();
}
break;
case 14: readcurser(&r1,&c1);
temp=track[cl-1]+c1-2;
delete1(temp);
c1=c1-1;
setcuserpos(r1,c1);
break;
case 15: a[p]=ac;
p++;
writechar(ac,23,r1,c1);
c=c1+8;
break;
case 72: if(cl!=1)
{ if(cl>fp)
{ cl--;
readcurser(&r1,&c1);
r1--;
setcuserpos(r1,c1);
}
else
{ fp--;
lp--;
cl--;
display();
// setcuserpos(r1,c1);
}
}
break;

case 80: if(cl!=t+1)
{ if(cl { cl++;
readcurser(&r1,&c1);
r1++;
setcuserpos(r1,c1);
}
else
{ fp++;
lp++;
cl++;
display();
}
}
break;

case 77: if(c1<78)
{ c1++;
setcuserpos(r1,c1);
}
else
{ eat++;
display();
}
break;

case 75: if(c1!=1)
{ if((eat+c1)>78)
{ eat--;
display();
}
else
{ c1--;
setcuserpos(r1,c1);
}
}
break;

default: if(track[cl-1]+c1-1+eat==p)
{ if(ac==13)
{ t++;
track[t]=track[t-1]+(eat+c1)-1;
k=t;
t--;
if(cl==lp)
{ fp++;
lp++;
display();
readcurser(&r1,&c1);
c1=1;
setcuserpos(r1,c1);
}

cl++;
if(eat!=0)
{ eat=0;
display();
}
t=k;
if(lp<=21)
{ readcurser(&r1,&c1);
r1=r1+1;
c1=1;
setcuserpos(r1,c1);
}

}
else
{ if((eat+c1)>= 78)
{ a[p]=ac;
eat++;
setcuserpos(r1,78);
display();
p++;
}
else
{ writechar(ac,23,r1,c1);
a[p]=ac;
p++;
c1++;
setcuserpos(r1,c1);
}
}
}
else
{ readcurser(&r1,&c1);
if((track[cl-1]+c1+eat)>track[cl])
{ readcurser(&r1,&c1);
temp=track[cl-1]+(c1+eat)-1;
for(i=track[cl];i insert(i,32);
}
if(ac!=13)
{ readcurser(&r1,&c1);
if(eat==0)
{ temp=track[cl-1]+c1-1;
insert(temp,ac);
display();
c1=c1+1;
setcuserpos(r1,c1);
}
else
{ temp=track[cl-1]+(c1+eat)-1;
insert(temp,ac);
eat++;
display();
c1=78;
setcuserpos(r1,c1);
}
}
else
{ memmove(track+(cl+1),track+cl,99-cl);
*(track+cl)=track[cl-1]+(c1+eat)-1;
t++;
r1=r1+1;
c1=1;
display();
setcuserpos(r1,c1);
cl++;
}
}
}
*r=r1;
*c=c1;
}
main()
{ int i,r,c,sc,c1,ac,k,m,exit=0;
union REGS inregs,outregs;
char far *v;
char *buff,*s[]= { "File",
"Edit",
"Search",
"View",
"Option",
"Help",
"Line:",
"Col:"
};

clrscr();
drawscreen();
track[t]=0;


c=3;
writestring(s[0],112,0,c); /*String,Attribute,Row No,Column No*/
c=9;
writestring(s[1],112,0,c);
c=15;
writestring(s[2],112,0,c);
c=23;
writestring(s[3],112,0,c);
c=29;
writestring(s[4],112,0,c);
c=37;
writestring(s[5],112,0,c);

writechar(179,112,24,58);
writestring(s[6],112,24,61);
writestring(s[7],112,24,70);
c=1; r=2;
setcuserpos(2,1);
while(!exit)
{ m=77;
drawbox(24,75,24,77,120);
c1=eat+c;
while(c1>0)
{ k=c1%10;
writechar(k+48,112,24,m);
c1=c1/10;
m--;
}
m=69;
r=cl;
drawbox(24,66,24,69,120);
while(r>0)
{ k=r%10;
writechar(k+48,112,24,m);
r=r/10;
m--;
}


getcharacter(&sc,&ac);

while(sc!=1 && ac==0 && sc!=77 && sc!=75 && sc!=72 && sc!=15 && sc!=80 && sc!=71 && sc!=79 && sc!=73 && sc!=81 && sc!=83 && sc!=14)
{ switch(sc)
{ case 33: writestring(s[0],32,0,3);
sc = Filemenu(buff);
if(sc==0)
exit=1;
writestring(s[0],112,0,3);
break;

case 18: writestring(s[1],32,0,9);
sc = Editmenu(buff);
writestring(s[1],112,0,9);
break;

case 31: writestring(s[2],32,0,15);
sc = Searchmenu(buff);
writestring(s[2],112,0,15);
break;

case 47: writestring(s[3],32,0,23);
sc = Viewmenu(buff);
writestring(s[3],112,0,23);
break;

case 24: writestring(s[4],32,0,29);
sc = Optionmenu(buff);
writestring(s[4],112,0,29);
break;

case 35: writestring(s[5],32,0,37);
sc = Helpmenu(buff);
writestring(s[5],112,0,37);
break;
default:
sc=1;
}
setcursersize(5,6);
}
if(sc!=1)
activescreen(sc,ac,&r,&c);
}
}

Related Links :

Shoot The Devil game in c

Shoot The Devil game in c




#include
#include
#include "graphics.h"
#include
#include
#include

void exitmessage(void);
void lost(void);

void main()
{
randomize();
int gd=DETECT,gm,no=0,area,maxx,maxy,chance=0;
int ch,x=25,y=25,xdir=1,ydir=1,x1=20,y1,x1dir=0,area1;
void *buff,*cuff;
initgraph(&gd,&gm,"bgi");
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(50,50,15); //
floodfill(50,50,WHITE);
arc(25,25,335,360,40);
arc(75,25,180,205,40);
circle(42,45,2);
circle(54,45,2);
setfillstyle(SOLID_FILL,BLACK);
floodfill(42,45,15);
floodfill(54,45,15); //draw devil
setcolor(10);
area=imagesize(25,25,75,75);
buff=malloc(area);
getimage(25,25,75,75,buff);
putimage(25,25,buff,XOR_PUT); //erase devil
maxx=getmaxx();
maxy=getmaxy();
y1=maxy/2;
setcolor(15);
setfillstyle(SOLID_FILL,15);
rectangle(10,y1,12,y1+2); //
floodfill(11,y1+1,15); //draw bullet
area1=imagesize(10,y1,12,y1+2);
cuff=malloc(area1);
getimage(10,y1,12,y1+2,cuff);
putimage(10,y1,cuff,XOR_PUT); //erase bullet
setcolor(14);
rectangle(0,0,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);
settextstyle(1,0,3);
settextjustify(1,1);
delay(4000);
setcolor(15);
while(no<100) no="0;" ch="getch();" ch="=" x1dir="1;" ch="=" x1dir="=" y1="y1-10;" ch="=" x1dir="=" y1="y1+10;" ch="=" x1="x1+10*x1dir;" x="x+(xdir*random(30));" y="y+(ydir*random(20));">=maxx-71) //keep devil within screen
{
xdir*=-1;
x=maxx-71;
}
if(x<=175&&xdir==1) x=175; if(x<=175&&xdir==-1) xdir*=-1; if(y>=maxy-71)
{
ydir*=-1;
y=maxy-71;
}
if(y<=30) { ydir*=-1; y=30; } // if(x1>=maxx-3||x<=1) //failed chance { x1=20; x1dir=0; } if(y1>=maxy-20) //keep gun within screen
y1=maxy-21;
if(y1<=20) y1=21; // if(x1<=x+40&&x1>=x+12&&y1<=y+38&&y1>=y+10) //successful hit
{
moveto(maxx/2,maxy/2);
outtextxy(maxx/2,maxy/2,"...YOU'VE...WON...");
sound(500);
delay(5000);
nosound();
delay(3000);
exit(0);
}
}
while(chance<=10); if(chance=11) lost(); getch(); closegraph(); restorecrtmode(); } void exitmessage() { char cho; outtextxy(getmaxx()/2,getmaxy()/2,"EXIT : Y or N..."); delay(100); flushall(); cho=getch(); if(cho=='y'||cho=='Y') exit(0); else if(cho=='n'||cho=='N') { clearviewport; return; } } void lost() { outtextxy(getmaxx()/2,getmaxy()/2-50,"Your bullets are over"); outtextxy(getmaxx()/2,getmaxy()/2,"The devil destroys the world"); }

Related Links :

Program Or Project to calculate Transportation Cost in c

Program to calculate Transportation Cost in c


#include
#include

main()
{
int flag=0,flag1=0;
int s[10],d[10],sn,eop=1,dm,a[10][10];
int i,j,sum=0,min,x[10][10],k,fa,fb;

clrscr();
/* Getting The Input For the Problem*/

printf("Enter the number of Supply
");
scanf("%d",&sn);
printf("Enter the number of Demand
");
scanf("%d",&dm);
printf("Enter the Supply Values
");
for(i=0;i=d[j]) //Check the supply greater than equal to
demand
{
x[i][j]=a[i][j]*d[j]; // Calculate amount * demand
s[i]=s[i]-d[j]; // Calculate supply - demand
j++; // Increment j for the deletion of the row
or
column
}

}
/* The Cost Matrix is Estimated here */
printf("Given Cost Matrix is :
");
for(fa=0;fa



Related Links :

Program to create tower of Hanoi in C

yle: italic;">Definition : The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.





#include
void hanoi_tower(char,char,char,int);
void hanoi_tower(char peg1,char peg2,char pege3,int n)
{
if(n<=0) printf("\n Sorry Illegal Entry"); if(n==1) printf ("\n Move disk from %c to %c", pege1,pege3); else { hanoi_tower(peg1,peg3,peg2,n-1); hanoi_tower(peg1,peg2,peg3,1); hanoi_tower(peg2,peg1,peg3,n-1); } } Void main () { int n; printf("\n Input the number of disc:); scanf("%d", &n); printf("\n Tower of Hanoi for 5th DISC", n); hanoi_tower('x','y','z',n); }

Related Links :

Ballon Fighter Game in C


Program to create Ballon Fighter Game in C, a lovely game, nice to play...Enjoy.. :)



# include "graphics.h"
# include "conio.h"
# include "stdio.h"
# include "stdlib.h"
# include "dos.h"
#define ARROW_SIZE 7
#define BALLOON_SIZE 3

int flag_arrow=0,flag_balloon=1,count_arrow=6,count_balloon=10;
void *balloon,*bow,*arrow,*burst;
void *clear_balloon,*clear_burst;
void draw_balloon(int ,int );
void draw_burst ( int x, int y );
void draw_bow(int x,int y);
void draw_arrow(int x, int y);
void shoot(int *x, int *y);
int testkeys();
void fly(int *x, int *y);
void start();

void main()
{
int gmode = DETECT, gdriver , area ;
initgraph ( &gmode, &gdriver, "c: c gi" ) ;
setbkcolor(1);
start();
int maxx = getmaxx() ;
int maxy = getmaxy() ;
int
p=400,q=300,m=100,n=100,x=m,y=n,key,score=0,finish=0,level=1,l_flag=1;
char score1[5],ch,cnt_ball[5],char_level[2];

rectangle ( 0, 0, maxx, maxy - 10 ) ;

draw_burst(200,300);
area=imagesize(0,0,32,24);
burst=malloc(area);
getimage(200-16,300-12,200+16,300+12,burst);
putimage(200-16,300-12,burst,XOR_PUT);

draw_balloon(p,q);

area=imagesize(p-4*BALLOON_SIZE,q-5*BALLOON_SIZE,p+4*BALLOON_SIZE,q+7*BALL
OON_SIZE);
balloon=malloc(area);

getimage(p-4*BALLOON_SIZE,q-5*BALLOON_SIZE,p+4*BALLOON_SIZE,q+7*BALLOON_SI
ZE,balloon);
putimage(p-4*BALLOON_SIZE, q-5*BALLOON_SIZE, balloon, COPY_PUT);

draw_arrow(x ,y );
area = imagesize(x, y-ARROW_SIZE, x+(6*ARROW_SIZE), y+ARROW_SIZE);
arrow=malloc(area);
getimage(x, y-ARROW_SIZE, x+(6*ARROW_SIZE), y+ARROW_SIZE,arrow);
putimage(x, y-ARROW_SIZE,arrow,XOR_PUT);

draw_bow(x,y);
area=imagesize(x+25,y-65,x+66,y+65);
bow=malloc(area);
getimage(x+25,y-65,x+66,y+65,bow);

if ( balloon == NULL || burst == NULL || bow == NULL )
{
printf( "
Insufficient memory... Press any key " ) ;
getch() ;
closegraph() ;
restorecrtmode() ;
exit( 0 ) ;
}

while (!finish)
{
settextstyle(8,0,1);
setusercharsize(4,4,3,3);
outtextxy(getmaxx()/2-100,5,"LEVEL : ");
itoa(level,char_level,10);
setfillstyle(0,0);
bar(getmaxx()/2+40,15,getmaxx()/2+70,45);
outtextxy(getmaxx()/2+50,5,char_level);

rectangle(5,360,250,460);

if( flag_balloon && count_balloon>0 )
fly( &p, &q );
else
{
q = 400;
flag_balloon = 1;
}

if( kbhit() )
{
key = testkeys();
if(key==77)
flag_arrow = 1;
}

if( key == 27 )
break;
if (key == 80 &&!flag_arrow)
{
x=125;
putimage(x,y-65,bow,XOR_PUT);
if(y<300) key="0;" key ="=" x="125;">70)
y-=25;
putimage(x,y-65,bow,XOR_PUT);
draw_bow(x-25,y);
key=0;
}
if(count_arrow > 0 && count_balloon > 0)
{
if(score==100 && l_flag==1)
{
level=2;
count_balloon=8;
count_arrow=6;
l_flag=2;
}
if(score==180 && l_flag==2)
{
level=3;
count_balloon=6;
count_arrow=6;
l_flag=0;
}
if( key == 77 || flag_arrow)
{
shoot(&x,&y);
draw_bow(m,y);
if(x>(p-12) && x<(p+12) && y>(q-15) && y<(q+25)) { putimage(p-16,q-12,burst,COPY_PUT); sound(1500); delay(800); nosound(); putimage(p-16,q-12,burst,XOR_PUT); count_balloon--; settextstyle(10,0,1); setusercharsize(30,70,20,70); outtextxy(20,380,"Yippee! BALLOONS LEFT:"); setfillstyle(0,0); bar(200,370,230,400); itoa(count_balloon,cnt_ball,10); outtextxy(200,380,cnt_ball); flag_balloon=0; score+=20; itoa(score,score1,10); setfillstyle(0,0); bar(190,getmaxy()-50,230,getmaxy()-30); setcolor(RED); outtextxy(20,getmaxy()-50,"SCORE : "); outtextxy(190,getmaxy()-50,score1); } key=0; } } else { clearviewport(); setbkcolor(9); setcolor(10); settextstyle(4,0,7); setusercharsize(120,50,120,40); outtextxy(getmaxx()/2-220,getmaxy()/2-180,"GAME OVER"); settextstyle(8,0,1); setusercharsize(50,60,40,50); if(count_arrow<=0) outtextxy(getmaxx()/2-100,getmaxy()/2-70,"NO MORE ARROWS"); if(count_balloon<=0) outtextxy(getmaxx()/2-120,getmaxy()/2-70,"NO MORE BALLOONS"); outtextxy(getmaxx()/2-120,getmaxy()/2-20,"YOUR SCORE IS : "); itoa(score,score1,10); outtextxy(getmaxx()/2+150,getmaxy()/2-20,score1); if(level==1) outtextxy(getmaxx()/2-220,getmaxy()/2+20,"YOU REQUIRE TO PRACTICE MORE"); if(level==2) outtextxy(getmaxx()/2-70,getmaxy()/2+20,"WELL PLAYED"); if(level==3) outtextxy(getmaxx()/2-220,getmaxy()/2+20,"YOU ARE AN EFFICIENT SHOOTER"); outtextxy(getmaxx()/2-30,getmaxy()/2+50,"(Q)UIT"); settextstyle(1,0,1); setusercharsize(30,65,30,60); outtextxy(30,430,"THIS GAME HAS BEEN DEVELOPED BY RUCHIR BINDAL AND VINAY KUMAR GUPTA"); outtextxy(230,450,"THIRD YEAR, COMPUTER SCIENCE AND ENGINEERING"); while( getch() != 'q'); finish=1; break; } } free(bow); free(arrow); free(balloon); closegraph(); } void draw_balloon(int x,int y) { setcolor(RED); setfillstyle(1,RED); fillellipse(x,y,3*BALLOON_SIZE,4*BALLOON_SIZE); line(x,y+4*BALLOON_SIZE,x,y+6*BALLOON_SIZE); } void draw_burst ( int x, int y ) { setlinestyle(0,0,1); line ( x - 16, y - 12, x - 10, y - 2 ) ; line ( x - 10, y - 2, x - 16, y ) ; line ( x - 16, y, x - 10, y + 2 ) ; line ( x - 10, y + 2, x - 16, y + 12 ) ; line ( x - 16, y + 12, x - 6, y + 2 ) ; line ( x - 6, y + 2, x, y + 12 ) ; line ( x, y + 12, x + 6, y + 2 ) ; line ( x + 6, y + 2, x + 16, y + 12 ) ; line ( x - 16, y - 12, x - 6, y - 2 ) ; line ( x - 6, y - 2, x, y - 12 ) ; line ( x, y - 12, x + 6, y - 2 ) ; line ( x + 6, y - 2, x + 16, y - 12 ) ; line ( x + 16, y - 12, x + 10, y - 2 ) ; line ( x + 10, y - 2, x + 16, y ) ; line ( x + 16, y, x + 10, y + 2 ) ; line ( x + 10, y + 2, x + 16, y + 12 ) ; } void draw_bow(int x,int y) { setcolor(RED); setlinestyle(0,0,1); line(x+32,y-49,x+32,y+49); setlinestyle(0,0,3); arc(x,y,300,60,60); arc(x+34,y-56,100,220,6); arc(x+34,y+56,140,260,6); } void shoot(int *x, int *y) { char cnt_arrow[5]; putimage(*x, *y-ARROW_SIZE, arrow, COPY_PUT); delay(3); putimage(*x, *y-ARROW_SIZE, arrow, XOR_PUT); *x+=ARROW_SIZE; if (*x>590)
{
*x=155;
flag_arrow=0;
count_arrow--;
settextstyle(10,0,1);
setusercharsize(30,70,20,70);
outtextxy(20,400,"ARROWS LEFT :");
setfillstyle(0,WHITE);
bar(200,400,220,425);
itoa(count_arrow,cnt_arrow,10);
outtextxy(200,400,cnt_arrow);
}

}
void draw_arrow(int x, int y)
{
setlinestyle(0,0,2);
moveto(x, y);
linerel(6*ARROW_SIZE, 0);
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE+1);
linerel(0, 2*ARROW_SIZE-1);
linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
}

int testkeys()
{
union REGS ii, oo ;
ii.h.ah = 0 ;
int86 ( 22, &ii, &oo ) ;
/* if ascii code is not 0 */
if ( oo.h.al )
return ( oo.h.al ) ; /* return ascii code */
else
return ( oo.h.ah ) ; /* return scan code */
}

void fly(int *x, int *y)
{
int x1;
putimage(*x-4*BALLOON_SIZE, *y-5*BALLOON_SIZE, balloon, COPY_PUT);
delay(20);
char cnt_ball[5];
putimage(*x-4*BALLOON_SIZE, *y-5*BALLOON_SIZE, balloon, XOR_PUT);
*y-=BALLOON_SIZE;

if(*y<= 20) { *y=400; x1=450+rand()%150; *x=x1; count_balloon--; settextstyle(10,0,1); setusercharsize(30,70,20,70); outtextxy(20,380,"BALLOONS LEFT:"); setfillstyle(0,0); bar(200,370,230,400); itoa(count_balloon,cnt_ball,10); outtextxy(200,380,cnt_ball); } } void start() { setbkcolor(0); settextstyle(7,0,0); outtextxy(10,400," PRESS ANY KEY TO CONTINUE...."); settextstyle(1,0,0); setcolor(4); setusercharsize(25,15,20,4); outtextxy(85,120,"BALLOON SHOOTING"); float octave[7] = { 130.81, 146.83, 164.81, 174.61, 196, 220, 246.94 }; while( !kbhit() ) { sound( octave[ random(7) ]*4 ); delay(300); } nosound(); getch(); clearviewport(); rectangle(1,1,638,478); settextstyle(3,0,1); setusercharsize(50,30,50,30); outtextxy(150,10,"INSTRUCTIONS"); setbkcolor(10); settextstyle(1,0,1); setusercharsize(40,70,20,20); outtextxy(10,70,"1. You can play three levels."); outtextxy(10,110,"2. You can move the bow UP and DOWN with the help of arrow keys."); outtextxy(10,150,"3. Press right arrow key to shoot the arrow."); outtextxy(10,190,"4. You score 20 points every time you shoot the balloon."); outtextxy(10,230,"5. First level has 6 arrows and 10 balloons."); outtextxy(10,270,"6. You require to score 100 points to enter the second level."); outtextxy(10,310,"7. Second level has 6 arrows and 8 balloons."); outtextxy(10,350,"8. You require to score 200 points to enter the third level."); outtextxy(10,390,"9. Third level has 6 arrows and 6 balloons."); settextstyle(7,0,1); outtextxy(150,430,"PRESS ANY KEY TO CONITINUE"); getch(); setusercharsize(1,1,1,1); settextstyle(0,0,0); setbkcolor(10); clearviewport(); }

Related Links :

String len



#include
#include
#include

#define PACKAGE "strl"
#define VERSION "1.0.0"

void print_help(int exval);

int main(int argc, char *argv[]) {
FILE *fp = stdin;
char line[1024];
int opt = 0;
int strip_newline = 0;

while((opt = getopt(argc, argv, "hvs")) != -1) {
switch(opt) {
case 'h':
print_help(0);
break;
case 'v':
fprintf(stdout, "%s %s\n", PACKAGE, VERSION);
exit(0);
break;
case 's':
strip_newline = 1;
break;
case '?':
fprintf(stderr, "%s: Error - No such option: `%c'\n\n", PACKAGE, optopt);
print_help(1);
break;
} /* switch */
} /* while */

if((argc - optind) == 0) {
while((fgets(line, 1024, fp)) != NULL) {
if(strip_newline == 1)
if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';

printf("%4d %s\n", strlen(line), line);
} /* while */
} else {
for(; optind < argc; optind++) {
if(freopen(argv[optind], "r", fp) == NULL) {
perror(argv[optind]);
continue;
}

while((fgets(line, 1024, fp)) != NULL) {
if(strip_newline == 1)
if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';

printf("%4d %s\n", strlen(line), line);
} /* while */
} /* for */
} /* else */

return 0;
}

void print_help(int exval) {
printf("%s,%s compute string length\n", PACKAGE, VERSION);
printf("Usage: %s [-h] [-v] [-s] FILE1 FILE2 ...\n\n", PACKAGE);

printf("Options:\n");
printf(" -h print this help and exit\n");
printf(" -v print version and exit\n");
printf(" -s strip trailing newlines\n\n");

printf(" If no filenames given, strings\n");
printf(" are read from stdin().\n\n");

printf(" This program does basicly the same as\n");
printf(" `${#varname}' in the GNU/Linux bash shell.\n\n");

exit(exval);
}

Related Links :

Dedekind ETA function


#include
#include
#include
#include

#define PACKAGE "eta"
#define VERSION "0.0.1"
#define MAXLINE 1024

/* Defination : The Dedekind eta function, named after Richard Dedekind, is a function defined on the upper half-plane of complex numbers, where the imaginary part is positive. */
void print_help(int exval);
/* print program version and exit with exval */
void print_version(int exval);
/* `\056' `float' detection ? */
/* returns -1 on error, 1 on `no dot', 0 on `dot' */
int is_float(char *val);

int main(int argc, char *argv[]) {
char line[MAXLINE]; /* fgets buff */
int overview_flag = 0; /* print overview only */
int count = 0; /* nr of input elements */
float total = 0; /* eta */
float num = 0; /* the actual element */
int opt = 0; /* parsed opt nr */
float highest = 0; /* the lowest encounterd nr */
float lowest = 0; /* the highest encounterd nr */

/* option parser */
while((opt = getopt(argc, argv, "hve")) != -1) {
switch(opt) {
case 'h': /* print help and exit */
print_help(0);
case 'v': /* print version and exit */
print_version(0);
case 'e':
overview_flag = 1;
break;
case '?':
fprintf(stderr, "%s: Error - No such option: `%c'\n\n", PACKAGE, optopt);
print_help(1);
}
}

/* no remaining argumenst left ? read stdin() */
if((argc - optind) == 0) {
while((fgets(line, MAXLINE, stdin)) != NULL) {
/* strip newlines */
if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';

count++;
if(is_float(line) == 0)
num = atof(line);
else
num = atoi(line);

if(count == 1) highest = num, lowest = num;

if(num > highest) highest = num;
if(num < lowest =" num;" num =" atoi(argv[optind]);" num =" atof(argv[optind]);" count ="="" highest =" num," lowest =" num;"> highest) highest = num;
if(num < lowest =" num;" overview_flag ="="" retval =" -1;" retval =" 1;" retval =" 0;">

Related Links :

Program to show implementation of singly linkedlist



/* implementation of singly linkedlist */
#include
#include
#include "linklist.h"

void release(linkedlist *lp)
{
while(lp -> count > 0)
del(lp, lp -> count);
}

node **goto_node(linkedlist *lp, int pos)
{
node *n = lp -> base, **curr = &(lp -> base);
if(pos < 0 || pos > lp -> count)
return NULL;

while(pos > 0)
{
curr = &(n -> next);
n = n -> next;
pos--;
}
return curr;
}

int append(linkedlist *lp, char *data)
{
node **curr = goto_node(lp, lp -> count);
*curr = (node *) malloc(sizeof(node));
if(*curr == NULL)
return FALSE;

strcpy((*curr) -> name, data);
(*curr) -> next = NULL;
lp -> count++;
return TRUE;
}

int insert(linkedlist *lp, int pos, char *data)
{
node **curr = goto_node(lp, pos - 1), *tmp;
if(curr == NULL)
return FALSE;
tmp = *curr;
*curr = (node *) malloc(sizeof(node));
if(*curr == NULL)
return FALSE;

strcpy((*curr) -> name, data);
(*curr) -> next = tmp;
lp -> count++;
return TRUE;
}

int del(linkedlist *lp, int pos)
{
node **curr = goto_node(lp, pos - 1), *tmp;
if(curr == NULL)
return FALSE;
tmp = *curr;
free(*curr);
*curr = tmp -> next;
lp -> count--;
return TRUE;
}

void show(linkedlist *lp)
{
node *n = lp -> base;
while(n != NULL)
{
printf("\n%s", n -> name);
n = n -> next;
}
}

int main(void)
{
int choice, pos;
char value[80];
linkedlist l = { NULL, 0 };
do
{
printf("\n ** SINGLE LINKED LIST **");
printf("\n1. Add\n2. Insert\n3. Remove\n4. Show\n5. Exit\nOption [1 - 5] ? ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nName :");
fflush(stdin);
gets(value);
if(!append(&l, value))
printf( "\nNode creation failed" );
else
printf( "\nNew node created successfully" );
break;
case 2:
printf("\nInsert position ? " );
scanf( "%d", &pos );
printf("\nEnter value :");
fflush(stdin);
gets(value);
if(!insert(&l, pos, value))
printf( "\nNode insertion failed" );
else
printf( "\nNode inserted successfully" );
break;
case 3:
printf("\nDelete position ? " );
scanf( "%d", &pos );
if(!del( &l, pos ))
printf( "\nNode removal failed" );
else
printf("\nNode removed successfully");
break;
case 4:
show(&l);
break;
case 5:
release(&l);
break;
}
}while(choice != 5);

return SUCCESS;
}

Related Links :

Airline Reservation System Project In C Language



#include
#include
#include

main()
{
FILE*fp,*ft;
char another,choice;
char name[20];
int tmp,x,fr,amt;

struct bnk
{
char name [20];
char add[20],dob[20],date[20];
int fcode,cl,fare;
int acno,c,fno,st,amt;
float ob,tk;
};
struct bnk e;
struct flt
{
char fname[20];
int fno,tk;
};
struct flt f;
long int recsize,recsize1;

fp=fopen("bnk.DAT","rb+");
if(fp==NULL)
{
fp=fopen("bnk.DAT","wb+");
exit();
}

recsize=sizeof(e);
recsize1=sizeof(f);
while(1)
{
int gd=DETECT,gm,maxx,maxy,x,y,button;
initgraph(&gd,&gm,"i:\tc\bin");
setbkcolor(1);
clrscr();
settextstyle(4,0,6);
outtextxy(200,1," Airline Reservation System ");
outtextxy(200,1," By IGCT Computers");
line(600,10,400,10);

printf("\n\n 1.New Customer");
printf("\n 2.List records");
printf("\n 3.New Flight ");
printf("\n 4.View Flight");
printf("\n 5.Delete records");
printf("\n 0.Exit");
printf("\n\n PLEASE ENTER YOUR CHOICE...\n ");
fflush (stdin);
choice=getche();
switch(choice)
{
case '1':
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
printf("\n Enter Customer Name...\n \t");
scanf("%s",&e.name);
printf("\n Enter Address...\n");
scanf("%s",&e.add);
printf("\n Enter DOB...\n");
scanf("%s",&e.dob);
printf("\nEnter Flight Code...\n");
scanf("%d",&e.fcode);
printf("\nEnter Date..\n");
scanf("%s",&e.date);
printf("\n Enter Class..\n");
scanf("%d",&e.cl);
printf("\nEnter Fare...\n");
scanf("%d",&fr);
printf("\n Enter Seats to Book..\n");
scanf("%d",&e.st);
if(e.cl==1)
{
e.fare=5000;
}
if(e.cl==2)
{
e.fare=3000;
}
else
{
e.fare=1000;
}
e.amt=e.fare+(e.st*fr)+(e.fare+.10);
printf("\n Total Payble amount with tax is %d",e.amt);
fwrite(&e,recsize,1,fp);
printf("\n Add Another Records(y/n)");
fflush(stdin);
another=getche();
}
break;

case '2':
printf("\nFCode\tName\tAddress\tDOB\tJ-Date\tClass\tSeats\tFare");
printf("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
printf("\n%d\t%s\t%s\t%s\t%s\t%d\t%d\t%d",e.fcode,e.name,e.add,e.dob,e.date,e.cl,e.st,e.amt);
getch();
break;


case '3':
fp=fopen("flt.DAT","rb+");
if(fp==NULL)
{
fp=fopen("flt.DAT","wb+");
exit();
}
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
printf("Enter Flight name,FLNO,Fare...\n");
scanf("%s %d %d",&f.fname,&f.fno,&f.tk);
fwrite(&f,recsize1,1,fp);
printf("\n Add Another Records(y/n)");
fflush(stdin);
another=getche();
}
break;

case '4':
printf("\nFlight Code \t FName \t Fare");
printf("\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*");
rewind(fp);
while(fread(&f,recsize1,1,fp)==1)
printf("\n %d \t %s \t %d",f.fno,f.fname,f.tk);
getch();
break;

case '5':
another ='y';
while(another=='y')
{
printf("\n enter name of Person to delete...\n");
scanf("%s",&name);
ft=fopen("pop.DAT","wb");
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{
if(strcmp(e.name,name)!=0)
fwrite(&e,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("bnk.DAT");
rename("pop.DAT","bnk.DAT");
fp=fopen("bnk.DAT","rb+");
printf("delete another record(y/n)");
fflush(stdin);
another=getche();
}
break;

case '0':
fclose(fp);
exit();
}
}
}

Related Links :

Project of ATM Banking System in C


#include
#include
char x;
int pin, repeat, menu;
int withdraw, deposit, transfer, amount;
main()


{ clrscr();
gotoxy(20,1);printf(":--------------------------------------:\n");
gotoxy(20,2);printf(": Welcome to ATM Banking System:\n");
gotoxy(20,3);printf(": Created by:\n");
gotoxy(20,4);printf(": ivan john Navasca:\n");
gotoxy(20,5);printf(": :\n");
gotoxy(20,6);printf(": Enter your PIN -->:\n");
gotoxy(20,7);printf(":--------------------------------------:\n");
gotoxy(40,6);
scanf(" %d",&pin);
if (pin==1234)
{printf("access granted");}
else
{exit();}
Loop:


{clrscr();
printf(":-------------------------------------------:\n");
printf(": Choose your Transaction :\n");
printf("::\n");
printf(": 1 Inquiry Balance :\n");
printf(": 2 Withdraw:\n");
printf(": 3 Deposit :\n");
printf(": 4 Transfer Fund:\n");
printf(": 5 Exit:\n");
printf(": -->:\n");
printf(":-------------------------------------------:\n");
gotoxy(6,9);
scanf(" %d",&menu);
printf("\n\n");
switch(menu)


{
case 1:{printf("Your balance %d\n\n",amount);
printf("Another transaction? y or n?: ");
scanf(" %c",&x);
if((x == 'y')||(x== 'Y'))


{
goto Loop;
}
else if((x =='n')||(x== 'N'))


{
printf("\nThank You for Banking");
getch();
exit();
}
break;}
case 2:{if(amount==0)
{printf("You have an Isuficient Fund\nPress Enter");
getch();
goto Loop;
}
else

{
printf("Your Balance %d\n\n",amount);
printf("Enter Amount to Withdraw: ");
scanf("%d",&withdraw);
amount = amount - withdraw;
printf("\nYour Current Balance %d\n\n",amount);
printf("Another Transaction? y or n : ");
scanf(" %c",&x);
if((x =='y')||(x=='Y'))


{
goto Loop;
}
else if ((x =='n')||(x=='N'))


{
printf("\nThank You for Banking");
getch();
exit();
} }
break;}
case 3:{printf("Your Balance %d\n",amount);
printf("\nEnter Amount to Deposit: ");
scanf("%d",&deposit);
amount= amount + deposit;
printf("\nYour Current Balance %d\n",amount);
printf("Another Transaction? y or n: ");
scanf(" %c",&x);
if ((x =='y')||(x=='Y'))


{
goto Loop;
}
else if ((x =='n')||(x=='N'))


{
printf("\n\nThank You for Banking");
getch();
exit();
}
break;}
case 4:{printf("Your Balance %d\n",amount);
printf("\nEnter Amount to Transfer: ");
scanf(" %d",&transfer);
amount = amount - transfer;
printf("\nYour Current Balance %d",amount);
printf("\n\nAnother Transaction? y or n: ");
scanf(" %c",&x);
if ((x =='y')||(x=='Y'))


{
goto Loop;
}
else if ((x =='n')||(x=='N'))


{
printf("Thank You for Banking");
getch();
exit();
}
break;}
case 5:{printf("You Want to Exit? y or n: ");
scanf(" %c",&x);
if ((x=='y')||(x=='Y'))


{
printf("\n\nThank You & Come Again");
getch();
exit();
}
else if ((x =='n')||(x=='N'))


{
goto Loop;
}
break;}
default:
exit();
}
}

while(repeat);
getch();
}





Related Links :


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!