-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.ino
73 lines (65 loc) · 1.99 KB
/
name.ino
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
const char *colors[] = {"blue",
"red",
"green",
"purple",
"orange",
"yellow",
"gold",
"pink",
"white",
"black",
"silver",
"gray",
"teal",
"aqua",
"violet",
"brown"
};
const char *vegetables[] = {"potato",
"sweetcorn",
"broccoli",
"tomato",
"carrot",
"bean",
"onion",
"pepper",
"pumpkin",
"lettuce",
"cabbage",
"celery",
"spinach",
"cucumber",
"leek",
"pea"
};
int subStrToInt(char *str, int position)
{
char hexNumber[2];
hexNumber[0] = str[position];
hexNumber[1] = '\0';
return (int)strtol(hexNumber, NULL, 16);
}
char * concatStr(char *str1, char *str2)
{
char * str = (char *) malloc(1 + strlen(str1) + strlen(str2));
strcpy(str, str1);
strcat(str, str2);
return str;
}
char * concatStr(char *str1, char *str2, char *str3)
{
char * str = (char *) malloc(1 + strlen(str1) + strlen(str2) + strlen(str3));
strcpy(str, str1);
strcat(str, str2);
strcat(str, str3);
return str;
}
char * generateName(char *macAddress)
{
int colorIndex = subStrToInt(macAddress, 15);
int vegetableIndex = subStrToInt(macAddress, 16);
return concatStr((char *) colors[colorIndex], "-", (char *) vegetables[vegetableIndex]);
}