0

input:
source:1.1.2.3:?:
destination:1.2.3.4
data:shfg hshsg h

am trying to extract 1.1.2.3 from source:1.1.2.3 please suggest :!:

    while(!mod.eof())
    {
        mod.getline(buf,100);
        if(strstr(buf,"Source"))
        {
         w=strchr(buf,':');
         strcpy(str,*w);
        }

    }

Edited by mike_2000_17: Fixed formatting

3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by Ancient Dragon
0

>>if(strstr(buf,"Source"))
watch the spelling and capatilization. strstr() is case-sensitive meaning Source and source are not the same thing.

char *ptr;
if( (ptr = strstr(buf, "source:") ) != NULL)
{
    // increment the ip address following the colon
    ptr += 6;
}
0

thnx a lot for the concern but i didn unders

ptr+=6
i want to copy the string in str variable
0

Compare the string with "source:" using strncmp() then use strcpy() using the form &buf[7] to point after source:

0

thnx a lot for the concern but i didn unders

ptr+=6
i want to copy the string in str variable

strstr() returns a pointer to the beginning of where "source:" begins. Since "source:" is 6 characters long, ptr+6 increments pointer ptr to the character immediately following the colon. Then all you have to do is copy the remainder of the string, beginning at ptr, to wherever you want it.i

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.