networking · intermediate · ~15 min
Parse a SIP response status.
A SIP response line mirrors HTTP: VERSION SP CODE SP REASON, e.g. SIP/2.0 200 OK. Extract the numeric status code.
Implement int sip_status_code(const char *line) that returns the numeric status from a SIP response line — the number after the first space.
A SIP response line line.
Returns the numeric status code, or -1 if line does not start with SIP/.
sip_status_code("SIP/2.0 200 OK") -> 200
sip_status_code("SIP/2.0 404 Not Found") -> 404
sip_status_code("garbage") -> -1
SIP/: return -1.A SIP response line.
The numeric status code, or -1 if the line does not start with 'SIP/'.
Require the 'SIP/' prefix; parse the integer after the first space.
#include <string.h>
#include <stdlib.h>
int sip_status_code(const char *line) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.