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

Why is c so powerful?

0 Answers  


Define recursion in c.

0 Answers  


what is printf

5 Answers   MVSR, Satyam,


Explain how do you determine a file’s attributes?

0 Answers  


why do some people write if(0 == x) instead of if(x == 0)?

0 Answers  






Explain how many levels deep can include files be nested?

0 Answers  


how to write hello word without using semicolon at the end?

6 Answers   Accenture,


What is self-referential structure in c programming?

0 Answers  


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,


What are different storage class specifiers in c?

0 Answers  


What are the advantages of c language?

0 Answers  


Explain the bubble sort algorithm.

0 Answers  


Categories