You can tokenise a string to extract specific fields, such as with:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char inpStr[] = "SETUP movie.Mjpeg RTSP/1.0 CSeq: 1"
" Transport: RTP/TCP; interleaved=0";
int main (void) {
char *name, *cseq;
strtok (inpStr, " "); // SETUP
name = strdup (strtok (NULL, " ")); // movie.Mjpeg
strtok (NULL, " "); // RTSP/1.0
strtok (NULL, " "); // CSeq:
cseq = strdup (strtok (NULL, " ")); // 1
printf ("Name is [%s], cseq is [%s]\n", name, cseq);
free (name);
free (cseq);
return 0;
}
The output of this is:
Name is [movie.Mjpeg], cseq is [1]
Basically, each call to strtok
will give you the address of the next token, suitably delimited. The call to strdup
(a) will ensure you get a duplicate of the string rather than a pointer to the original string. Using a pointer to the original string would mean changes to one would affect the other.
Keep in mind this alters the original string so, if you don't want that, make sure you use a copy.
(a) Standard C does not provide strdup
although it's available in many implementations. If your implementation doesn't have one, see here.