I corrected your code. You made some mistakes as Adak said. Another one thing, You are avoiding the 0th index in an array. Is there any specific reason for this?. This is not a problem in your code. But you allocated the static memory to the array.After allocated the memory other's can't use the memory space. But why you didn't use the space?.This may be a problem while you writing a big code.(project).Please avoid to miss the index in an array.This is my opinion.
Code:
#include <stdio.h>
#include <string.h>
int main()
{
struct Payroll_System
{
char fname[40], sname[40], mi[2];
int id, bpay;
}
emp[5];
int z=0 , x, y;
char sel;
char choice;
do
{
printf("PAYROLL SYSTEM\n\n");
printf("MENU:\n 1. Enter Employees Record\n 2. Process Payroll\n 3. Payroll Summary\n 4. Employee Payslip\n 5. Exit\n");
printf("Enter your choice: ");
choice=getc(stdin);
switch(choice)
{
case '1':
do
{
printf("%d\n",z);
printf("Write Record \n\n\n");
printf("Employee Number: ");
scanf("%i", &emp[z].id);
printf("Employee Name\n");
printf("First Name: ");
scanf("%s", &emp[z].fname);
printf("Middle Initial: ");
scanf("%s", &emp[z].mi);
printf("Last Name: ");
scanf("%s", &emp[z].sname);
printf("Basic Pay (Daily): ");
scanf("%i", &emp[z].bpay);
printf("Employee: %s, %s %s \nSuccessfully Added!\n\n\n", emp[z].sname, emp[z].fname, emp[z].mi);
printf("Add New Record (y/n): ");
getchar();
scanf("%c",&sel);
z++;
}
while(sel != 'n');
break;
case '2':
printf("Process Payroll \n\n\n");
printf("Enter Employee Number: ");
scanf("%d", &y);
for(x=0;x<z;x++)
{
if(y == emp[x].id)
{
printf("Employee Name: %s, %s %s", emp[x].sname, emp[x].fname, emp[x].mi);
}
}
break;
}
}
while(choice!= '5');
}