user123123123
user123123123

Reputation: 23

Extracting a set of characters/string from a character array

I am having trouble with my C programming and I would like some help in extracting a set of characters from a character array. The following below is in a character array:

POST / HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 11
Origin: http://localhost:8081
Connection: keep-alive
Referer: http://localhost:8081/
Upgrade-Insecure-Requests: 1
textbox=asd

I would like to extract "asd" from this entire chunk, how do I do this? Also, do note that the characters "asd" can be changed to any character or length. Please help..

Upvotes: 2

Views: 55

Answers (1)

mkayaalp
mkayaalp

Reputation: 2736

You can use strstr to search for textbox= and copy the rest of the string with strdup:

char *p = strstr(str, "textbox=");
if (p)
    char *t = strdup(p+sizeof("textbox=")-1);

Upvotes: 2

Related Questions