-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompany.c
62 lines (52 loc) · 1.79 KB
/
company.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
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "company.h"
#define MAX_COMPANIES 50
#define MAX_POSITIONS 80
#define MAX_EMPLOYEES 100
#define MAX_INPUT_SIZE 250
Company companies[MAX_COMPANIES];
int companyCount = 0;
// Company functions--------------------
void createCompany(int id, const char *name, const char *location, const char *industry) {
if (companyCount >= MAX_COMPANIES) {
printf("Error: Maximum company limit reached.\n");
return;
}
companies[companyCount].id = id;
strncpy(companies[companyCount].name, name, sizeof(companies[companyCount].name));
strncpy(companies[companyCount].location, location, sizeof(companies[companyCount].location));
strncpy(companies[companyCount].industry, industry, sizeof(companies[companyCount].industry));
companyCount++;
printf("Company '%s' added successfully.\n", name);
}
void listCompanies() {
if (companyCount == 0) {
printf("No companies available.\n");
return;
}
printf("----------List of Companies:----------\n");
for (int i = 0; i < companyCount; i++) {
printf("ID: %d, Name: %s, Location: %s, Industry: %s\n",
companies[i].id, companies[i].name, companies[i].location, companies[i].industry);
}
}
void deleteCompany(int id) {
int found = 0;
for (int i = 0; i < companyCount; i++) {
if (companies[i].id == id) {
found = 1;
// Shift remaining companies
for (int j = i; j < companyCount - 1; j++) {
companies[j] = companies[j + 1];
}
companyCount--;
printf("Company with ID %d deleted successfully.\n", id);
break;
}
}
if (!found) {
printf("Error: Company with ID %d not found.\n", id);
}
}