Source Code
Source Code
#include <stdlib.h>
#include <conio.h>
/**
function : gotoxy
*/
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
int main()
struct emp
};
* if the file EMP.DAT already exists then it open that file in read write mode
*/
fp = fopen("EMP.DAT","rb+");
if(fp == NULL)
fp = fopen("EMP.DAT","wb+");
if(fp == NULL)
exit(1);
}
/// sizeo of each record i.e. size of structure variable e
recsize = sizeof(e);
while(1)
gotoxy(30,10); /// move the cursor to postion 30, 10 from top-left corner
gotoxy(30,12);
gotoxy(30,14);
gotoxy(30,16);
gotoxy(30,18);
gotoxy(30,20);
switch(choice)
system("cls");
fseek(fp,0,SEEK_END); /// search the file and move cursor to end of the file
/// here 0 indicates moving 0 distance from the end of the file
another = 'y';
scanf("%s",e.name);
scanf("%d", &e.age);
scanf("%f", &e.bs);
fflush(stdin);
another = getche();
break;
case '2':
system("cls");
while(fread(&e,recsize,1,fp)==1) /// read the file and fetch the record one record per fetch
printf("\n%s %d %.2f",e.name,e.age,e.bs); /// print the name, age and basic salary
getch();
break;
system("cls");
another = 'y';
while(another == 'y')
scanf("%s", empname);
rewind(fp);
scanf("%s%d%f",e.name,&e.age,&e.bs);
fseek(fp,-recsize,SEEK_CUR); /// move the cursor 1 step back from current position
break;
fflush(stdin);
another = getche();
break;
case '4':
system("cls");
another = 'y';
while(another == 'y')
scanf("%s",empname);
ft = fopen("Temp.dat","wb"); /// create a intermediate file for temporary storage
fwrite(&e,recsize,1,ft); /// move all records except the one that is to be deleted to temp
file
fclose(fp);
fclose(ft);
fp = fopen("EMP.DAT", "rb+");
fflush(stdin);
another = getche();
break;
case '5':
return 0;