Database Management Using C+
Database Management Using C+
MANAGEMENT
using
C+
CONTENTS
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>
#include<c:\database\vdu.h>
struct rec
int code;
int q;
float cost;
}r;
void display(),list(int*),addn(),dele(int),modify(int);
int count=1,nor=0,count1=0,pagecount=1;
void main()
char ch;
while(1)
{
fflush(stdin);
ch=getch();
if(ch==0)
fflush(stdin);
switch(ch)
break;
// nor++;
break;
if((nor>18)&&(count%18==1)&&(count!=1))
clr();
}
dele(count);
nor--;
if(count<1)
count=1;
clr();
break;
clr();
break;
if((nor>18)&&(count%18==1)&&(count!=1))
pagecount--;
clr();
if((nor>18)&&(count==1))
else
count--;
if((count<1)&&(nor<=18))
count=nor;
break;
pagecount++;
clr();
if((pagecount>1)&&(count==nor))
else
count++;
if((count>nor)&&(nor<=18))
count=1;
break;
void display()
int i,k[5]={2,8,18,27,13},j=0;
char q[5][25];
_setcursortype(_NOCURSOR);
sbox(1,1,80,24);
textcolor(15);
textbackground(5);
gotoxy(18,2);
sline1(1,3,80,3);
for(i=0;i<5;i++)
j=j+k[i];
gotoxy(j,4);
textcolor(15);
textbackground(6);
cprintf("%s",q[i]);
sline1(1,5,80,5);
sline1(8,3,8,24);
plus(8,5);
sline1(26,3,26,24);
plus(26,5);
sline1(53,3,53,24);
plus(53,5);
sline1(66,3,66,24);
plus(66,5);
textcolor(15);
textbackground(6);
gotoxy(1,25);
cprintf(" ");
gotoxy(1,25);
textcolor(2);
cprintf(" N ");
textcolor(15);
gotoxy(20,25);
textcolor(2);
cprintf(" D ");
textcolor(15);
cprintf("Delete Record");
gotoxy(37,25);
textcolor(2);
cprintf(" R ");
textcolor(15);
textcolor(2);
cprintf(" M ");
textcolor(15);
cprintf("Modify Record");
}
void list(int *c)
int j[5]={2,8,19,27,12},i=0,rp=0,m=0,rc=0;
FILE *fp;
recsize=sizeof(r);
count1++;
fp=fopen(datafile,"rb+");
if(fp==NULL)
clr();
gotoxy(3,5);
printf("\nFile Creation Error\n\nPlease verify and set the path of ur data.dat file\nif the file does not
exist,create a dummy file as data.dat keep it in the \npath specified above or u can change the path
in the #define statement\nif u know where the file exists\nPress ESC to exit.");
rewind(fp);
while(fread(&r,recsize,1,fp)==1)
i=0;
m=0;
if(count1==1)
rc++;
if(rp==(*c))
textcolor(15);
textbackground(10);
else
textcolor(15);
textbackground(0);
m=m+j[i];
gotoxy(m,rc+5);
cprintf("%d.",rp);
i++;
m=m+j[i];
gotoxy(m,rc+5);
cprintf("%d",r.code);
i++;
m=m+j[i];
gotoxy(m,rc+5);
cprintf("%s",r.name);
i++;
m=m+j[i];
gotoxy(m,rc+5);
cprintf("%d",r.q);
i++;
m=m+j[i];
gotoxy(m,rc+5);
cprintf("%.2f",r.cost);
fcloseall();
void addn()
FILE *fp;
struct rec r;
char vh='y';
fp=fopen(datafile,"rb+");
fseek(fp,0,SEEK_END);
recsize=sizeof(r);
while(vh=='y'||vh=='Y')
{
clr();
_setcursortype(_NORMALCURSOR);
scanf("%d",&r.code);
scanf("%s",r.name);
scanf("%d",&r.q);
scanf("%f",&r.cost);
fwrite(&r,recsize,1,fp);
nor++;
fflush(stdin);
vh=getch();
fcloseall();
clr();
FILE *fp,*ft;
struct rec r;
long int recsize;
int k=0;
recsize=sizeof(r);
fp=fopen(datafile,"rb+");
ft=fopen(tempfile,"wb+");
rewind(fp);
while(fread(&r,recsize,1,fp)==1)
k++;
if(k!=count)
fwrite(&r,recsize,1,ft);
fclose(fp);
fclose(ft);
remove(datafile);
rename(tempfile,datafile);
FILE *fp;
int k=0;
struct rec r;
recsize=sizeof(r);
fp=fopen(datafile,"rb+");
_setcursortype(_NORMALCURSOR);
rewind(fp);
while(fread(&r,recsize,1,fp)==1)
k++;
if(k==count)
clr();
scanf("%d",&r.code);
scanf("%s",r.name);
scanf("%d",&r.q);
scanf("%f",&r.cost);
fseek(fp,-recsize,SEEK_CUR);
fwrite(&r,recsize,1,fp);
}
SCREENSHOT