write a own function for strstr



write a own function for strstr..

Answer / 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

More C Interview Questions

Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

0 Answers  


What is a far pointer?What is the utility?

4 Answers  


how can i sort numbers from ascending order and descending order using turbo c..

1 Answers  


what is an inline fuction??

2 Answers  


What language is lisp written in?

0 Answers  






Can one function call another?

0 Answers  


Can a variable be both const and volatile?

0 Answers  


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

0 Answers  


What is array in c with example?

0 Answers  


How can I direct output to the printer?

0 Answers  


what is c programming?

3 Answers   TCS,


Which header file should you include if you are to develop a function which can accept variable number of arguments?

0 Answers   TCS, TISL,


Categories