#include
#include
#define PACKAGE "colconv"
int main(int argc, char *argv[]) {
char color[7];
char red[2], green[2], blue[2];
int r, g, b;
r = g = b = 0;
if(argc == 1)
fprintf(stdout, "usage: %s HEXCOLOR\n", PACKAGE), exit(1);
if(strlen(argv[1]) != 6)
printf("Invalid nr: %s\n", argv[1]), exit(1);
else
strncpy(color, argv[1], 6);
red[0] = color[0], red[1] = color[1], red[2] = '\0';
sscanf(red, "%X", &r);
printf("Red : %d\n", r);
green[0] = color[2], green[1] = color[3], green[2] = '\0';
sscanf(green, "%X", &g);
printf("Green : %d\n", g);
blue[0] = color[4], blue[1] = color[5], blue[2] = '\0';
sscanf(blue, "%X", &b);
printf("Blue : %d\n", b);
return 0;
}
#include
#define PACKAGE "colconv"
int main(int argc, char *argv[]) {
char color[7];
char red[2], green[2], blue[2];
int r, g, b;
r = g = b = 0;
if(argc == 1)
fprintf(stdout, "usage: %s HEXCOLOR\n", PACKAGE), exit(1);
if(strlen(argv[1]) != 6)
printf("Invalid nr: %s\n", argv[1]), exit(1);
else
strncpy(color, argv[1], 6);
red[0] = color[0], red[1] = color[1], red[2] = '\0';
sscanf(red, "%X", &r);
printf("Red : %d\n", r);
green[0] = color[2], green[1] = color[3], green[2] = '\0';
sscanf(green, "%X", &g);
printf("Green : %d\n", g);
blue[0] = color[4], blue[1] = color[5], blue[2] = '\0';
sscanf(blue, "%X", &b);
printf("Blue : %d\n", b);
return 0;
}
No comments:
Post a Comment