Hi,guys!!now i wish to make a program that can intput data into the array of structure......firstly, i can input the data and then print it at once,but when i come back to the choice function,it seems can't print more a record ,hope some people can help me !!
I have attached the file named by a2obackup.c
/***The program is under below***/
#include<stdio.h>
#define SIZE 10 /*The number of record is 10*/
struct name{
char first[30];
char last[30];
};
struct datehire{
char day[2];
char month[2];
char year[4];
};
struct employee{
struct name allname;
char id[20];
char salary[20];
struct datehire alldate;
};
typedef struct employee Employee;
void choice();
void addrecord(Employee *);
void changerecord(Employee *);
void loada(Employee *);
void loadall(Employee *);
main(void){
choice();
return 0;
}
void choice(){ /*choice function that used to led the user to choice the function*/
Employee employee_list[SIZE];
int choice;
int rubbish;
do{
printf(" <--------Welcome to employee database system--------> \n\n");
printf(" Please choose the number of function that you want->\n\n");
printf(" <1>Add Record/Records\n");
printf(" <2>Change a Record\n");
printf(" <3>Load A record to screen\n");
printf(" <4>Load ALL record to screen\n");
printf(" <5>Exit\n");
printf("\n\n\nPlease enter:->");
scanf("%d",&choice);
switch(choice){
case 1:
addrecord(employee_list);
break;
case 2:
changerecord(employee_list);
break;
case 3:
loada(employee_list);
break;
case 4:
loadall(employee_list);
break;
case 5:
printf("Exited,thanks you to using our system!\n");
printf("press any key and then press the enter to exit\n");
scanf("%d",&rubbish);
break;
default:
printf("Error input!Please input the number between 1-5");
scanf("%d",&rubbish);
}
}while (choice!=5);
}
void addrecord(Employee *employee_list){/*add a record*/
int count=0;
int display=0;
printf("Enter employee name(First name)->");
scanf("%s",employee_list[count].allname.first);
printf("Enter employee name(Last name)->");
scanf("%s",employee_list[count].allname.last);
printf("Enter the the employee id->");
scanf("%s",employee_list[count].id);
printf("Enter the employee salary->");
scanf("%s",employee_list[count].salary);
printf("Please enter the date of hire->");
scanf("%s%s%s",&employee_list[count].alldate.day,&employee_list[count].alldate.month,&employee_list[count].alldate.year);
printf("\n");
printf("The record [%d] employee first name -> %s \n",display+1,employee_list[count].allname.first);
printf("The record [%d] employee last name -> %s\n",display+1,employee_list[count].allname.last);
printf("The record [%d] employee id ->%s \n",display+1,employee_list[count].id);
printf("The record [%d] employee salary -> %s\n",display+1,employee_list[count].salary);
printf("The record [%d] employee hire of date-> %s/%s/%s\n",display+1,employee_list[count].alldate.day,employee_list[count].alldate.month,employee_list[count].alldate.year);
printf("\n");
count=count+1;
display=display+1;
}
void changerecord(Employee *employee_list){ /*change the existed record*/
int choice1;
char check;
printf("What record do you want to change?Enter the number of record please->");
scanf("%d",&choice1);
printf("You want to change record %d\n",choice1);
--choice1;
printf("Enter employee name(First name) to change the orignal record:\n");
scanf("%s",employee_list[choice1].allname.first);
printf("Enter employee name(Last name) to change the orignal:\n");
scanf("%s",employee_list[choice1].allname.last);
printf("Enter the the employee id to change the orignal\n");
scanf("%s",employee_list[choice1].id);
printf("Enter the employee salary to change the orignal\n");
scanf("%s",employee_list[choice1].salary);
printf("Please enter the date of hire\n");
scanf("%s%s%s",&employee_list[choice1].alldate.day,&employee_list[choice1].alldate.month,&employee_list[choice1].alldate.year);
printf("The orignal have changed,Do you want to check it?Y or N\n");
scanf("%s",&check);
if((check=='Y')||(check=='y')){
printf("The record [%d] first name-> %s \n",choice1+1,employee_list[choice1].allname.first);
printf("The record [%d] last name-> %s\n",choice1+1,employee_list[choice1].allname.last);
printf("The record [%d] id-> %s\n",choice1+1,employee_list[choice1].id);
printf("The record [%d] salary-> %s\n",choice1+1,employee_list[choice1].salary);
printf("The record [%d] date of hire-> %s/%s/%s\n",choice1+1,employee_list[choice1].alldate.day,employee_list[choice1].alldate.month,employee_list[choice1].alldate.year);
printf("End of change record");
printf("\n\n\n\n\n\n");
}
}
void loada(Employee *employee_list)
{
int choice1;
printf("What record do you want to load to screen?Enter the number of record please->");
scanf("%d",&choice1);
choice1-1;
printf("%s ",employee_list[choice1].allname.first);
printf("%s\n",employee_list[choice1].allname.last);
printf("%s\n",employee_list[choice1].id);
printf("%s\n",employee_list[choice1].salary);
printf("%s/%s/%s\n",employee_list[choice1].alldate.day,employee_list[choice1].alldate.month,employee_list[choice1].alldate.year);
}
void loadall(Employee *employee_list){
}