forked from ChicoState/ColorPalette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
46 lines (39 loc) · 1020 Bytes
/
main.cpp
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
#include <iostream>
#include <cstring>
using namespace std;
bool all_hex(char*);
int main(int argc, char* argv[]) {
int valid_colors = 0;
if(argc < 2) {
cout << "ERR_MISSING: One or more RGB values should be provided as arguments, separated by spaces" << endl;
return -1;
}
for(int i=1; i < argc; i++) {
int length = strlen(argv[i]);
if(length == 3 || length == 6) {
if(all_hex(argv[i])) {
cout << "#" << argv[i] << endl;
}
else {
cout << argv[i] << " ERR_VALUE: RGB values must be in 0-F range" << endl;
}
}
else {
cout << argv[i] << " ERR_LENGTH: RGB values must be either 3 or 6 characters long" << endl;
}
}
return 0;
}
bool all_hex(char* word) {
for(int i=0; i<strlen(word); i++) {
if((word[i] >= '0' && word[i] <= '9') || (word[i] >= 'a' && word[i] <= 'f')
|| (word[i] >= 'A' && word[i] <='F')) {
continue;
}
else {
return false;
}
}
//no non-hex characters found
return true;
}