networking · beginner · ~15 min
Tokenise an IPv6 address by ':'.
Count the colon-separated groups (hextets) in a fully written IPv6 address.
Implement int count_groups(const char *addr). The address is in full form (no :: compression), so the answer is simply the number of colons plus 1.
addr: an IPv6 address string in full (uncompressed) form.The count of :-separated groups.
count_groups("2001:db8:0:0:0:0:0:1") -> 8
count_groups("a:b:c") -> 3
addr: an IPv6 address string in full (uncompressed) form.
The number of ':'-separated groups (colons + 1).
Assume full form with no '::' compression.
int count_groups(const char *addr) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.