blob: 0dca6488de8ad48d5fe0863515c4194b0e8adda1 (
plain) (
blame)
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
|
#include <iostream>
#include <cstring>
#include "User.h"
void UserArray::add(const User& user) {
if (count >= allocated) {
std::cout << "No more users are allowed!" << std::endl;
return;
}
users[count++] = user;
}
User* UserArray::find(char* username) {
for (unsigned i = 0; i < count; ++i)
if (strcmp(username, users[i].name) == 0)
return &users[i];
return nullptr;
}
UserArray newUserArray(unsigned allocatedSize) {
UserArray ua;
ua.users = new User[allocatedSize];
ua.count = 0;
ua.allocated = allocatedSize;
return ua;
}
void deleteUserArray(UserArray& ua) {
delete[] ua.users;
ua.users = nullptr;
ua.count = ua.allocated = 0;
}
|