Sunday, December 8, 2013

Working of strstr function

strstr() is a function used to copy location of a specific word in a string to a pointer variable.
Header file: string.h
The function's prototype is as follows
 char * strstr (char * str1, const char * str2 );  
str1 is the string to be scanned
str2 is string containing the specific word or character

For example:
Let str[30]="This is a sample"
Let address of str[0] be equal to 2000
Let 'ptr' be a pointer variable pointing to character data[char * ptr]

Now using strstr()
 ptr=strstr(str,"sample");  
This returns address 2010 to ptr (because in str address 2010 points to 's' of sample)
If the match is not found, strstr() returns a NULL pointer.

Tags:-strstr(),c programming,address copying