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

difference between ordinary variable and pointer in C?

2 Answers  


What is meaning of tree

0 Answers  


what is the function of void main()?

8 Answers  


How can a program be made to print the line number where an error occurs?

1 Answers  


What is the difference between malloc() and calloc() function in c language?

1 Answers  


What is variables in c?

1 Answers  


what is the difference between arrays and linked list

26 Answers   MAHINDRA, Tech Mahindra, Wipro,


how can write all 1to 100 prime numbers using for loop,if and break ?

2 Answers   TCS,


how can be easily placed in TCS.

0 Answers   TCS,


write a c program to find the roots of a quadratic equation ax2 + bx + c = 0

11 Answers   CSC, St Marys, TATA,


What are variables and it what way is it different from constants?

1 Answers  


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

1 Answers  


Categories