sorry hit the wrong key.....I agree with Hammer, do not use scanf. This function is not necessary in most cases. Take a look at this code....it is for a similiar program to your current project.
Code:
/*----------code---------------*/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "a:\CrtUtil.h"
/* ---------------------------- */
/* DEFINE FUNCTION PROTOTYPES */
/* ---------------------------- */
int HouseKeeping();
void Process(void);
void Heading(void);
void EndJob(void);
void Display(void);
/* ------------------------------ */
/* DEFINE PAYROLL RECORD FORMAT */
/* ------------------------------ */
typedef enum {Active, Inactive}Status;
typedef enum {Hourly, Salaried, Exempt}Class;
typedef struct
{
Status Status2;
char Soc_Sec[10];
char Last_Name[14];
char First_Name[12];
char Initial;
char Birth_Date[9];
char Sen_Date[9];
int Dept_Num;
char Sex;
int Citizen;
int Depend;
float Pay;
Class Employee_Class;
} Payroll_Record_Type;
/* ------------------------- */
/* DEFINE GLOBAL VARIABLES */
/* ------------------------- */
FILE *Payroll_File;
Payroll_Record_Type Pay_Record;
int Counter = 0;
char Male;
char Female;
int Exempt_Counter = 0;
int Salaried_Counter = 0;
int Hourly_Counter = 0;
/* ------------------------------ */
/* MAIN LINE PROCESSING ROUTINE */
/* ------------------------------ */
void main()
{
HouseKeeping();
while ( !feof(Payroll_File) )
Process();
EndJob();
}
/* ------------------------- */
/* HOUSEKEEPING SUBROUTINE */
/* ------------------------- */
int HouseKeeping()
{
textattr (0X1E);
clrscr();
Payroll_File = fopen("Payroll.Dat", "rb");
if (Payroll_File == NULL )
{
printf( "Cannot open payroll file...\n");
exit( EXIT_FAILURE );
}
Heading();
fread( &Pay_Record, sizeof(Pay_Record), 1, Payroll_File );
Counter = 0;
return 0;
}
/* --------------------------- */
/* DETAIL PROCESSING ROUTINE */
/* --------------------------- */
void Process()
{
if (Pay_Record.Status2 == Active )
{
Display();
}
fread( &Pay_Record, sizeof(Pay_Record), 1, Payroll_File );
}
/* --------------------------- */
/* END OF JOB ROUTINE */
/* --------------------------- */
void EndJob()
{
printf("\nTOTAL NUMBER OF ACTIVE EMPLOYEES..: %d\n\n", Counter);
printf("EXEMPT: %d SALARIED: %d HOURLY: %d\n", Exempt_Counter, Salaried_Counter, Hourly_Counter );
fclose(Payroll_File );
}
/*----------------------------*/
/* HEADING ROUTINE */
/*----------------------------*/
void Heading()
{
printf(" EMPLOYEE DISPLAY \n\n");
printf("SOC. SEC. DEPT LAST NAME FIRST NAME I SEX DP CIT CLASS. PAY SEN. DATE\n\n");
}
/*----------------------------*/
/* DISPLAY ROUTINE */
/*----------------------------*/
void Display()
{
printf("%.3s-%.2s-%4s ",
Pay_Record.Soc_Sec,
Pay_Record.Soc_Sec+3,
Pay_Record.Soc_Sec+5 );
printf("%.3d ", Pay_Record.Dept_Num);
printf("%-13s ", Pay_Record.Last_Name);
printf("%-11s ", Pay_Record.First_Name);
printf("%c" , Pay_Record.Initial);
printf("%3c", Pay_Record.Sex);
printf("%4d", Pay_Record.Depend);
{
if (Pay_Record.Citizen == 1)
printf( " Yes" );
else
printf(" No ");
}
switch (Pay_Record.Employee_Class)
{
case Hourly: printf("HRLY");
Hourly_Counter++;
break;
case Salaried: printf("SAL.");
Salaried_Counter++;
break;
case Exempt: printf("EXMT");
Exempt_Counter++;
break;
}
printf("%9.2f", Pay_Record.Pay);
printf("%4.2s/%.2s/%.4s",
Pay_Record.Sen_Date + 4,
Pay_Record.Sen_Date + 6,
Pay_Record.Sen_Date);
Counter = Counter + 1;
}
/*----------end oc code-------------*/
Hope this sheds a little light!
Code tags added by Hammer