Hi, I am trying to get an employee database to work correctly, I thought that all the coding was correct but everytime I run my code i get a return of -1, help would be appreciated: -
#include <stdio.h>
-
-
typedef struct Employee
-
{
-
char fname[20];
-
char lname[20];
-
char sub_taken[20];
-
char last_edu[20];
-
char join_date[20];
-
int id;
-
int age;
-
float bsal;
-
}Employee;
-
-
int main(void)
-
{
-
-
int id;
-
FILE *fp,*ft;
-
char another,choice;
-
Employee emp;
-
char fname[20];
-
char lname[20];
-
long int recsize;
-
-
fp=fopen("EMP.DAT","rb+");
-
if(fp==NULL)
-
{
-
fp=fopen( "EMP.DAT","wb+");
-
if(fp==NULL)
-
{
-
printf("
-
Can't Open File");
-
exit();
-
}
-
}
-
recsize=sizeof(emp);
-
while(1)
-
{
-
printf("
-
1.Add Records
-
2.Delete Records
-
3.Modify Records
-
-
4.List
-
Records
-
5.Exit");
-
printf("
-
-
Enter your choice");
-
fflush(stdin);
-
scanf("%c",&choice);
-
switch(choice)
-
{
-
case'1':
-
fseek(fp,0,SEEK_END);
-
another='Y';
-
while(another=='Y'|| another=='y')
-
{
-
printf("Enter the first name,last name,age and basic salary : ");
-
scanf("%s %d %f",emp.fname,&emp.age,&emp.bsal);
-
printf("
-
Enter joining date,id,last education,subject taken");
-
scanf("%s %d %s %s",emp.join_date,&emp.id,emp.last_edu,
-
emp.sub_taken);
-
fwrite(&emp,recsize,1,fp);
-
printf("
-
Add another Record (Y/N): ");
-
fflush(stdin);
-
another=getchar();
-
}
-
-
break;
-
case '2':
-
another='Y';
-
while(another=='Y'|| another=='y')
-
{
-
printf("
-
Enter the id of the employee to be deleted : ");
-
scanf("%d",&id);
-
ft=fopen("TEMP.DAT","wb");
-
rewind(fp);
-
while(fread(&emp,recsize,1,fp)==1)
-
{
-
if(strcmp(emp.id,id)!=0)
-
fwrite(&emp,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=getchar();
-
}
-
-
break;
-
case '3':
-
another='Y';
-
while(another=='Y'|| another=='y')
-
{
-
printf("
-
Enter name of employee to modify : ");
-
scanf("%s",emp.fname);
-
rewind(fp);
-
while(fread(&emp,recsize,1,fp)==1)
-
{
-
if(strcmp(emp.id,id)==0)
-
{
-
printf("
-
Enter new fname,new lname,age,basic
-
salary,joining_date,subject taken and last education : ");
-
-
scanf("%s%s%d%f%s%s%s",emp.fname,emp.lname,&emp.age,&emp.bsal,emp.join_dat
-
e,emp.sub_taken,emp.last_edu);
-
fseek(fp,-recsize,SEEK_CUR);
-
fwrite(&emp,recsize,1,fp);
-
break;
-
}
-
}
-
printf("
-
Want to Modify another record(Y/N): ");
-
fflush(stdin);
-
another=getchar();
-
}
-
-
break;
-
-
case '4':
-
-
rewind(fp);
-
while(fread(&emp,recsize,1,fp)==1)
-
printf("
-
%s %s %d
-
%g",emp.fname,emp.lname,emp.age,emp.bsal,emp.join_date,emp.last_edu,emp.su
-
b_taken);
-
break;
-
-
case '5':
-
fclose(fp);
-
exit();
-
-
}
-
}
-
}
1 2978
Your code won't even compile.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jonnie |
last post by:
I am in the process of building an employee database for use by the
management team here. They current have Access 97 (I am working on
getting them to upgrade to at least 2000). For the most part I...
|
by: RR |
last post by:
I am wondering what tables and relationships I would have to have to keep
track of one or several employees commissions per transaction.
One tracsaction can have one or several employees work on...
|
by: Chris Strug |
last post by:
Hi,
As something of a pet project, I'm looking to develop a tool to track
employee holiday (or vacation for those of us in the US) for my company -
good for the company (if I get something...
|
by: RSH |
last post by:
I am really trying to grasp the concept of OOP as it applies to C#.
I am looking at trying to set up a simple Employee Class but I am having
trouble conceptualizing what this class should look...
|
by: Akinyemi |
last post by:
I am creating a database in MSAccess 2000 for my Payroll Program I am writing. I want to save an image representing an employee in the record of each employee. I then want to post the name of each...
|
by: Maddy |
last post by:
I manage a small organisation of around 100 employees, with different
specialisations. It becomes difficult to check how many persons of
each specialisation are available at any time, based on...
|
by: andrewCMF |
last post by:
Hello
I hope this is posted in the correct place, if not the can some point
me in the direction of a suitable Google group.
ok, here's my problem......
When an employee logs into their PC,...
|
by: petepell |
last post by:
Hello all,
I am developing an application in VB 2008 that works with a SQL2005 DB to store and manipulate employee data. In one section of the app I want to be able to show a treeview of the...
|
by: JennDavila |
last post by:
Hello,
I am running into an issue with adding a form that displays a calendar to where the manager can click a day and it will attach itself to a tracking table. I am new to this and have been...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |