ex-03: Comment code
This commit is contained in:
parent
cfadb53fa9
commit
dea9ea660e
@ -40,6 +40,7 @@ int main() {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Strip out any whitespaces
|
||||
char* dst = input;
|
||||
for(char * src = input; *src; src++) {
|
||||
if(!isspace(*src)) {
|
||||
@ -49,6 +50,10 @@ 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();
|
||||
@ -60,10 +65,13 @@ 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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user