Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a own function for strstr

Answer Posted / abdur rab

#include <stdio.h>

char* str_str ( char* cp_str, char* cp_pattern )
{
char* cp_temp = NULL;
int n_pattern_length = 0;

n_pattern_length = strlen ( cp_pattern );

while ( cp_str && *cp_str ) {
if ( !strncmp ( cp_str, cp_pattern, (
n_pattern_length ) ) ) {
cp_temp = cp_str;
break;
}
else cp_str++;
}

return ( cp_temp );

}

int main ( int argc, char* argv [ ] )
{
char array [] = {"Hello World"};
char* cp_temp = NULL;

cp_temp = str_str ( array, "lo " );
if ( NULL != cp_temp ) {
printf ("\n%s", cp_temp);
} else printf ("\nReturned null");

return ( 0 );

}

Is This Answer Correct ?    12 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does 3 periods mean in texting?

1054


What is scope rule of function in c?

1084


Can a void pointer point to a function?

1016


Why do we use int main instead of void main in c?

1139


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

2147


what are the different storage classes in c?

1177


What is structure pointer in c?

1046


Is malloc memset faster than calloc?

1063


What is the use of printf() and scanf() functions?

1121


When would you use a pointer to a function?

1041


What is the argument of a function in c?

1045


All technical questions

1983


What should malloc() do? Return a null pointer or a pointer to 0 bytes?

1064


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

1104


Explain how can a program be made to print the name of a source file where an error occurs?

1191