forked from ChicoState/ColorPalette
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
33 lines (27 loc) · 639 Bytes
/
main.cpp
File metadata and controls
33 lines (27 loc) · 639 Bytes
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>
using namespace std;
bool all_hex(char*);
int main(int argc, char* argv[]) {
int valid_colors = 0;
for(int i=1; i < argc; i++) {
int length = strlen(argv[i]);
if( (length == 3 || length == 6) && all_hex(argv[i]) ) {
cout << "#" << argv[i] << 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;
}