cybersecurity · beginner · ~15 min · safe pentest lab
Count elements in XML output.
Summarise scan coverage by counting how many hosts a saved nmap XML report contains.
Implement int count_hosts(const char *xml) that returns the number of <host opening tags in xml.
xml: a NUL-terminated string holding saved nmap XML, baked into the harness.Returns int: the count of <host substrings.
count_hosts("<host>a</host><host>b</host>") -> 2
count_hosts("<ports/>") -> 0
A NUL-terminated string xml of saved nmap output.
An int: the number of <host opening tags.
Count the substring <host. Static buffer only.
#include <string.h>
int count_hosts(const char *xml) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.