473,657 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Employee database

2 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. typedef struct Employee
  4. {
  5.     char fname[20];
  6.     char lname[20];
  7.     char sub_taken[20];
  8.     char last_edu[20];
  9.     char join_date[20];
  10.     int id;
  11.     int age;
  12.     float bsal;
  13. }Employee;
  14.  
  15. int main(void)
  16. {
  17.  
  18.     int id;
  19.     FILE *fp,*ft;
  20.     char another,choice;
  21.     Employee emp;
  22.     char fname[20];
  23.     char lname[20];
  24.     long int recsize;
  25.  
  26.     fp=fopen("EMP.DAT","rb+");
  27.     if(fp==NULL)
  28.     {
  29.         fp=fopen( "EMP.DAT","wb+");
  30.         if(fp==NULL)
  31.         {
  32.             printf("
  33. Can't Open File");
  34.             exit();
  35.         }
  36.     }
  37.     recsize=sizeof(emp);
  38.     while(1)
  39.     {
  40.         printf("
  41. 1.Add Records 
  42. 2.Delete Records 
  43. 3.Modify Records 
  44.  
  45. 4.List
  46. Records 
  47. 5.Exit");
  48.         printf("
  49.  
  50. Enter your choice");
  51.         fflush(stdin);
  52.         scanf("%c",&choice);
  53.         switch(choice)
  54.         {
  55.             case'1':
  56.                 fseek(fp,0,SEEK_END);
  57.                 another='Y';
  58.                 while(another=='Y'|| another=='y')
  59.                 {
  60.                     printf("Enter the first name,last name,age and basic salary : ");
  61.                     scanf("%s %d %f",emp.fname,&emp.age,&emp.bsal);
  62.                     printf("
  63.  Enter joining date,id,last education,subject taken");
  64.                     scanf("%s %d %s %s",emp.join_date,&emp.id,emp.last_edu,
  65.                     emp.sub_taken);
  66.                     fwrite(&emp,recsize,1,fp);
  67.                     printf("
  68.  Add another Record (Y/N): ");
  69.                     fflush(stdin);
  70.                     another=getchar();
  71.                 }
  72.  
  73.                 break;
  74.             case '2':
  75.                 another='Y';
  76.                 while(another=='Y'|| another=='y')
  77.                 {
  78.                     printf("
  79.  Enter the id of the employee to be deleted : ");
  80.                     scanf("%d",&id);
  81.                     ft=fopen("TEMP.DAT","wb");
  82.                     rewind(fp);
  83.                     while(fread(&emp,recsize,1,fp)==1)
  84.                     {
  85.                         if(strcmp(emp.id,id)!=0)
  86.                         fwrite(&emp,recsize,1,ft);
  87.                     }
  88.                     fclose(fp);
  89.                     fclose(ft);
  90.                     remove("EMP.DAT");
  91.                     rename("TEMP.DAT","EMP.DAT");
  92.                     fp=fopen("EMP.DAT","rb+");
  93.                     printf("Delete another Record(Y/N): ");
  94.                     fflush(stdin);
  95.                     another=getchar();
  96.                 }
  97.  
  98.                 break;
  99.              case '3':
  100.                 another='Y';
  101.                 while(another=='Y'|| another=='y')
  102.                 {
  103.                     printf("
  104.  Enter name of employee to modify : ");
  105.                     scanf("%s",emp.fname);
  106.                     rewind(fp);
  107.                     while(fread(&emp,recsize,1,fp)==1)
  108.                     {
  109.                         if(strcmp(emp.id,id)==0)
  110.                         {
  111.                             printf("
  112.  Enter new fname,new lname,age,basic
  113. salary,joining_date,subject taken and last education : ");
  114.  
  115. scanf("%s%s%d%f%s%s%s",emp.fname,emp.lname,&emp.age,&emp.bsal,emp.join_dat
  116. e,emp.sub_taken,emp.last_edu);
  117.                             fseek(fp,-recsize,SEEK_CUR);
  118.                             fwrite(&emp,recsize,1,fp);
  119.                             break;
  120.                          }
  121.                      }
  122.                      printf("
  123. Want to Modify another record(Y/N): ");
  124.                      fflush(stdin);
  125.                      another=getchar();
  126.                  }
  127.  
  128.                  break;
  129.  
  130.               case '4':
  131.  
  132.                    rewind(fp);
  133.                    while(fread(&emp,recsize,1,fp)==1)
  134.                    printf("
  135. %s %s %d
  136. %g",emp.fname,emp.lname,emp.age,emp.bsal,emp.join_date,emp.last_edu,emp.su
  137. b_taken);
  138.                    break;
  139.  
  140.              case '5':
  141.                 fclose(fp);
  142.                 exit();
  143.  
  144.         }
  145.     }
  146.  }
Dec 20 '07 #1
1 2995
weaknessforcats
9,208 Recognized Expert Moderator Expert
Your code won't even compile.
Dec 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1735
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 have it under control. There are several points that have popped up as wanted features and I need to verify somethings. 1. We now want to add the ability to add comments/notes with time and date stamps to an employees record. These comments...
2
1420
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 it, and the commissions for each employee depends on how many employees worked on it. Thanks
1
14922
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 usuable working) and good practice for me. Before I even open Access I want to get the relationships sorted. First looks indicate two basic entities:
17
19284
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 like. I was hoping someone might be able to simply outline what I envision my class to look like: Basically I am envisioning a Class called Employee: I imagine it would have many properties(?) such as:
3
1532
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 employee and the image I have save in each record of each employee on Visual Basic Form. How do I do this? I need your help. Akinyemi
2
4134
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 their vacation period. So I have made a ms-acces database as follows - A table EMPL with details of employees. A table SPEC with the various specialisations. The EMPL table has a specialisation field linked to the SPEC table. Finally a VACATION...
7
2307
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, we want to record the "log in" time and then the "log off" time at the end of the day and record the two times in a SQL Database. This is for the purpose of working out
0
1659
petepell
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 hierarchy as a whole showing a nested hierarchy of who reports to who such that when it is first loaded, all you will see is the top guy in the company with a plus next to his name. Opening that will reveal his first level reports and opening those will...
2
3736
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 given this project as a learning exp. I need all the help I can get on where to begin. I have created tables- one of with employee information, another with reason codes for day off requests (such as jury duty, vacation, sick time, etc). And a table...
0
8407
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.