Employee Project in C

#include "stdio.h"
main()
{
FILE*fp,*ft;
char another,choice;

struct emp
{
char name [20];
int age;
float bs;
};

struct emp e;
char empname[40];
long int recsize;
fp=fopen("EMP.DAT","rb+");

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

recsize=sizeof(e);

while(1)
{
clrscr();
printf("\n 1.Add records");
printf("\n 2.List records");
printf("\n 3.Modifay records");
printf("\n 4.Delete records");
printf("\n 0.Exit");
printf("\n Enter your choice");

fflush (stdin);
choice=getche();

switch(choice)
{
case '1':
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
printf("\n enter name age and basic salary");
scanf("%s %d %f",&e.name,&e.age,&e.bs);
fwrite(&e,recsize,1,fp);
printf("\n add another records(y/n)");
fflush(stdin);
another=getche();
}
break;

case '2':
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
printf("\n %s %d %f",e.name,e.age,e.bs);
getch();
break;

case '3':
another='y';
while(another=='y')
{
printf("\n enter name of employee to modify");
scanf("%s",&empname);

rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{
if(strcmp(e.name,empname)==0)
{
printf("\n enter new name age and bs");
scanf("%s %d %f",&e.name,&e.age,&e.bs);
fseek(fp,-recsize,SEEK_CUR);
fwrite(&e,recsize,1,fp);
break;
}
}
printf("\nmodify another record(y/n)");
fflush(stdin);
another=getche();
}
break;

case '4':

another ='y';
while(another=='y')
{
printf("\n enter name of employee to delete");
scanf("%s",&empname);
ft=fopen("TEMP.DAT","wb");
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{
if(strcmp(e.name,empname)!=0)
fwrite(&e,recsize,1,ft);
}
fclose(fp);
fclose(ft);

remove("EMP.DAT");
rename("TEMP.DAT","EMP.DAT");

fp=fopen("EMP.DAT","rb+");
printf("delete another record(y/n)");
fflush(stdin);
another=getche();
}
break;
case '0':
fclose(fp);
exit();
}
}
}

Related Links :

No comments:

Post a Comment


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!!!