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 |
How does C++ help with the tradeoff of safety vs. usability?
Where is volatile variable stored?
What is wrong with this program statement?
What is the difference between macros and inline functions?
How do I initialize a pointer to a function?
How to print "Hi World" without using semi colon?
How to set a variable in the environment list?
how can i include my own .h file EX:- alex.h like #include<alex.h>, rather than #include"alex.h"
Write a program to generate the Fibinocci Series
Write a code to generate a series where the next element is the sum of last k terms.
what is c?
writw a program to insert an element in the begning of a doubly linked list