-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path022_struct_basics.c
52 lines (40 loc) · 1.56 KB
/
022_struct_basics.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// with functions
#include <stdio.h>
struct employee {
char employeeName[50];
char employeeDateOfJoin[20];
float employeeSalary;
};
void getDataFromUser(int employeeNumber);
void printDataObtainedFromUser(int employeeNumber, char employeeName[50], char employeeDateOfJoin[20], float employeeSalary);
void getDataFromUser(int employeeNumber) {
struct employee emp;
printf("Enter Name of Employee Number %i: ", employeeNumber);
scanf("%s", emp.employeeName);
// printf("\n");
printf("Enter Date of Join of Employee Number %i: ", employeeNumber);
scanf("%s", emp.employeeDateOfJoin);
// printf("\n");
printf("Enter Salary of Employee Number %i: ", employeeNumber);
scanf("%f", &emp.employeeSalary);
// printf("\n");
printDataObtainedFromUser(employeeNumber, emp.employeeName, emp.employeeDateOfJoin, emp.employeeSalary);
}
void printDataObtainedFromUser(int employeeNumber, char employeeName[50], char employeeDateOfJoin[20], float employeeSalary) {
printf("\nDETAILS OF EMPLOYEE NUMBER %i: \n", employeeNumber);
printf("1> Name: %s \n2> Date of Join: %s\n3> Salary: %f \n", employeeName, employeeDateOfJoin, employeeSalary);
printf("\n~*~*~*~*~*~*~*~*~*~*~*~*~ \n \n");
}
int main() {
int noOfEmployees = 0;
int employeeNumber;
char employeeName[50];
char employeeDateOfJoin[12];
float employeeSalary;
printf("Enter the number of employees: ");
scanf("%i", &noOfEmployees);
printf("\n~*~*~*~*~*~*~*~*~*~*~*~*~ \n \n");
for (employeeNumber = 1; employeeNumber <= noOfEmployees; employeeNumber++) {
getDataFromUser(employeeNumber);
}
}