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);
        }

    }

>>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;
}

thnx a lot for the concern but i didn unders

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

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

thnx got the point :cheesy:

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