Don’t know about C, but in Perl you have to print your “Set-Cookie” line in the HTTP header, before the blank line that delimits the start of the body, as in
So I think your set-cookie is fine as long as it’s being output as part of the header.
To retrieve the cookie, you read the HTTP_COOKIE environment variable and parse the key/value pairs out of it just like you’d parse key/value pairs out of form input. That may be your problem, if you’re reading the wrong environment variable.
The trivial first thing to check is that your test browser is set to accept cookies.