-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
130 lines (118 loc) · 4.56 KB
/
main.c
File metadata and controls
130 lines (118 loc) · 4.56 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Unix shell for the managment system of a company
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "company.h"
#include "employee.h"
#include "position.h"
#define MAX_COMPANIES 50
#define MAX_POSITIONS 80
#define MAX_EMPLOYEES 100
#define MAX_INPUT_SIZE 250
void parseCommand(char *input) {
// Remove newline from input
input[strcspn(input, "\n")] = '\0';
// Tokenize input
char *command = strtok(input, " ");
if (command == NULL) {
printf("No command entered.\n");
return;
}
// Handle commands
if (strcmp(command, "add-company") == 0) {
int id;
char name[50], location[50], industry[30];
printf("Enter ID, Name, Location, and Industry: ");
scanf("%d %49s %49s %29s", &id, name, location, industry);
createCompany(id, name, location, industry);
} else if (strcmp(command, "list-companies") == 0) {
listCompanies();
} else if (strcmp(command, "delete-company") == 0) {
int id;
printf("Enter Company ID to delete: ");
scanf("%d", &id);
deleteCompany(id);
} else if (strcmp(command, "add-position") == 0) {
int id, companyId;
char title[50];
float minSalary, maxSalary;
printf("Enter ID, Company ID, Title, Min Salary, and Max Salary: ");
scanf("%d %d %49s %f %f", &id, &companyId, title, &minSalary, &maxSalary);
addPosition(id, companyId, title, minSalary, maxSalary);
} else if (strcmp(command, "list-positions") == 0) {
int companyId;
printf("Enter Company ID (-1 for all): ");
scanf("%d", &companyId);
listPositions(companyId);
} else if (strcmp(command, "delete-position") == 0) {
int id;
printf("Enter Position ID to delete: ");
scanf("%d", &id);
deletePosition(id);
} else if (strcmp(command, "add-employee") == 0) {
int id, positionId;
char name[50];
float salary;
printf("Enter ID, Name, Position ID, and Salary: ");
scanf("%d %49s %d %f", &id, name, &positionId, &salary);
addEmployee(id, name, positionId, salary);
} else if (strcmp(command, "list-employees") == 0) {
int positionId;
printf("Enter Position ID (-1 for all): ");
scanf("%d", &positionId);
listEmployees(positionId);
} else if (strcmp(command, "delete-employee") == 0) {
int id;
printf("Enter Employee ID to delete: ");
scanf("%d", &id);
deleteEmployee(id);
} else if (strcmp(command, "update-salary") == 0) {
int id;
float newSalary;
printf("Enter Employee ID and New Salary: ");
scanf("%d %f", &id, &newSalary);
updateEmployeeSalary(id, newSalary);
} else {
printf("Unknown command: %s\n", command);
}
// Clear input buffer
while (getchar() != '\n');
}
int main() {
char input[MAX_INPUT_SIZE];
printf("Welcome to the Company Management System!\n");
printf("Enter commands (type 'exit' to quit and 'help' to see commands):\n");
while (1) {
printf("> ");
if (fgets(input, sizeof(input), stdin) == NULL) {
break; // Handle EOF and prevent an infinite loop
}
// Remove trailing newline character
input[strcspn(input, "\n")] = '\0';
// Check for exit command
if (strncmp(input, "exit", 4) == 0) {
printf("Exiting system. Goodbye!\n");
break;
}
// Check for help command
if (strcmp(input, "help") == 0) {
printf("\nAvailable Commands:\n");
printf(" add-company - Add a new company\n");
printf(" list-companies - List all companies\n");
printf(" delete-company - Delete a company by ID\n");
printf(" add-position - Add a new position to a company\n");
printf(" list-positions - List all positions (or by company ID)\n");
printf(" delete-position - Delete a position by ID\n");
printf(" add-employee - Add a new employee to a position\n");
printf(" list-employees - List all employees (or by position ID)\n");
printf(" delete-employee - Delete an employee by ID\n");
printf(" update-salary - Update an employee's salary\n");
printf(" exit - Quit the system\n");
printf(" help - Display this help message\n\n");
continue;
}
// Parse and execute the command
parseCommand(input);
}
return 0;
}