2025-10-10 14:39:35 +02:00

41 lines
864 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#ifdef __PROGTEST__
#define debug(...) ((void)0)
#else
#define debug(fmt, ...) fprintf(stdout, "[DEBUG %s:%d %s()] " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#endif
bool is_in_rgb_range(int color) {
return color >= 0 && color <= 255;
}
int invalid_input() {
printf("Nespravny vstup.\n");
return EXIT_FAILURE;
}
int main() {
int r = -1, g = -1, b = -1;
printf("Zadejte barvu v RGB formatu:\n");
int inputs_read = scanf(" rgb ( %d , %d , %d )", &r, &g, &b);
if(inputs_read != 3) {
debug("Not enough inputs read");
return invalid_input();
}
if(!is_in_rgb_range(r) || !is_in_rgb_range(g) || !is_in_rgb_range(b)) {
debug("Number not in range of rgb [0, 255]");
return invalid_input();
}
printf("#%02X%02X%02X\n", r, g, b);
return EXIT_SUCCESS;
}