Tuesday, 11 December 2012

Implement strstr

/*This program will find the substring s2 from the string s1
* and if found the it reutrns the base address of the substring
* if not found it send zero as a character pointer.
* */
char *mystrstr(const char *string, const char *needle)
const char *s1;//For retaing address of second sring for checking
const char *tar; //For retaing address of first string
/*Loop untill end*/
for(; *string != '\0'; string++){
for(s1 = string, tar = needle; *tar != '\0'; s1++, tar++){
if(*s1 != *tar)
if(*tar == '\0')
return (char *)s1;
return NULL;

No comments:

Post a Comment