Compare commits

..

7 Commits

Author SHA1 Message Date
Tomáš Kléger
3a1e87fa24 ex-03: Added solution for rgb converter 2025-10-07 09:39:43 +02:00
Tomáš Kléger
d5710a0b14 ex-03: Add test data 2025-10-07 09:37:55 +02:00
Tomáš Kléger
f287f0952e ex-03: Added assignment detail 2025-10-07 09:37:51 +02:00
Tomáš Kléger
6f61da04ff hw-00: Free buffer 2025-10-07 09:34:16 +02:00
Tomáš Kléger
a46cabebdf hw-00: Fix bad pointer comparison 2025-10-07 09:34:14 +02:00
Tomáš Kléger
81310b9d79 hw-00: Comment code 2025-10-07 09:34:11 +02:00
Tomáš Kléger
60427b7841 hw-00: Use getline and strtol instead to account for special cases 2025-10-07 09:33:55 +02:00

View File

@ -40,7 +40,6 @@ int main() {
return EXIT_FAILURE;
}
// Strip out any whitespaces
char* dst = input;
for(char * src = input; *src; src++) {
if(!isspace(*src)) {
@ -50,10 +49,6 @@ int main() {
*dst = '\0';
int trimmed_len = strlen(input);
// Check whether the provided input
// starts with rgb(
// and ends with )
if(strncmp(input, "rgb(", 4) != 0 || input[trimmed_len - 1] != ')') {
debug("%s not in rgb(xxx) format", input);
return invalid_input();
@ -65,13 +60,10 @@ int main() {
char* token = strtok(slice, ",");
for(int i = 0; i < 3; i++) {
// strtok reached end prematurely
if(token == NULL) {
debug("Too few numbers");
return invalid_input();
}
// Not a number
if(!is_numeric(token)) {
debug("%s is not a number", token);
return invalid_input();