networking · intermediate · ~15 min
Validate a whole hostname.
Implement int hostname_valid(const char *h) returning 1 if h is non-empty and every character is a valid hostname character (letters, digits, '-', '.'), else 0.
int hostname_valid(const char *h) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.