#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char* msg = "HTTP/1.1 200 OK\r\n"
            "Date: Sat, 04 Jun 2016 13:07:05 GMT\r\n"
            "Server: Apache\r\n"
            "X-Powered-By: PHP/5.5.35\r\n"
            "Content-Length: 2\r\n"
            "Connection: close\r\n"
            "Content-Type: text/html\r\n"
            "\r\n"
            "11\r\n";
    
    // lookup the content-length header
    char* content = strstr(msg, "Content-Length: ");
    // skip the looked up string:
    content = content+strlen("Content-Length: ");
    // store the size of the contents in number of characters
    int nb_chars = atoi(content);
    // lookup the content
    content = strstr(msg, "\r\n\r\n");
    // check that the substring has been found
    if (content == NULL) {
        printf("Couldn't find the contents within the message!");
    } else {
        // skip the header-content delimiter
        content = content+4;
        // and do useful things with the extracted data
        if (nb_chars == 2) {
            printf("The content is:");
            printf("%s\n", content);
        } else {
            printf("There's been an error processing the request.");
        }
    }

	return 0;
}
