473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Employee database

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 2978
weaknessforcats
9,208 Expert Mod 8TB
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
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...
2
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...
1
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...
17
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...
3
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...
2
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...
7
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,...
0
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.