-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path02_input_employee_data.c
50 lines (40 loc) · 1.14 KB
/
02_input_employee_data.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
// // Write a function to take input employee data from the user. [ Refer structure from question 1 ]
// // Header Files
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define MAX_CHAR_NAME 31
// // Define Structure
struct Employee
{
int id;
char name[MAX_CHAR_NAME];
double salary;
};
// // Functions Declarations (Prototypes)
void inputEmployee(struct Employee *);
// // Main Function Start
int main()
{
// // create variable of structure Employee
struct Employee emp1;
// // Input Employee Data
puts("\n>>>>>> Enter Employee's Data <<<<<<<");
inputEmployee(&emp1);
putch('\n');
getch();
return 0;
}
// // Main Function End
// // Function to Input Employee data
void inputEmployee(struct Employee *emp)
{
printf("\nEnter Employee's Id => ");
scanf("%d", &emp->id);
printf("Enter Employee's Name (MAX CHARACTERS %d) => ", MAX_CHAR_NAME - 1);
fflush(stdin);
fgets(emp->name, MAX_CHAR_NAME, stdin); // // Input String
emp->name[strcspn(emp->name, "\n")] = '\0'; // // Replace '\n' character with '\0'
printf("Enter Employee's Salary => ");
scanf("%lf", &emp->salary);
}