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

hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..

1461


How can I find the modification date and time of a file?

596


What is #define used for in c?

609


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

14949


How is a pointer variable declared?

588






What are derived data types in c?

604


Why is %d used in c?

559


how we can make 3d venturing graphics on outer interface

3994


What is the difference between fread buffer() and fwrite buffer()?

665


Why is not a pointer null after calling free?

587


What are the general description for loop statement and available loop types in c?

678


Explain goto?

708


What do you mean by dynamic memory allocation in c?

643


Explain how to reverse singly link list.

601


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

756