#include <stdio.h>
#include <string.h>
int get_string_between_two_substrings(const char *str)
{
const char *PATTERN1 = "LOCATION: ";
const char *PATTERN2 = ".xml";
char target[100];
char *start, *end;
memset(target, '\0', sizeof(target));
/* start would point to the beginning of the substring in the main string. */
if ( start = strstr( str, PATTERN1 ) )
{
/* move the start pointer to string length(PATTERN) times ahead.
* Now, start points to the beginning of the text be searched.
*/
start += strlen( PATTERN1 );
/* Now, search for pattern 2. end points to the beginning of PATTERN2 */
if ( end = strstr( start, PATTERN2 ) )
{
/* Now, copy the text between PATTERN1 and PATTERN2 */
memcpy( target, start, end - start );
target[end - start] = '\0';
}
}
if ( target ) printf( "%s\n", target );
return 0;
}
void main(void)
{
const char *s = "LOCATION: http://192.168.1.197:8008/ssdp/device-desc.xml";
get_string_between_two_substrings(s);
return;
}
#include <string.h>
int get_string_between_two_substrings(const char *str)
{
const char *PATTERN1 = "LOCATION: ";
const char *PATTERN2 = ".xml";
char target[100];
char *start, *end;
memset(target, '\0', sizeof(target));
/* start would point to the beginning of the substring in the main string. */
if ( start = strstr( str, PATTERN1 ) )
{
/* move the start pointer to string length(PATTERN) times ahead.
* Now, start points to the beginning of the text be searched.
*/
start += strlen( PATTERN1 );
/* Now, search for pattern 2. end points to the beginning of PATTERN2 */
if ( end = strstr( start, PATTERN2 ) )
{
/* Now, copy the text between PATTERN1 and PATTERN2 */
memcpy( target, start, end - start );
target[end - start] = '\0';
}
}
if ( target ) printf( "%s\n", target );
return 0;
}
void main(void)
{
const char *s = "LOCATION: http://192.168.1.197:8008/ssdp/device-desc.xml";
get_string_between_two_substrings(s);
return;
}