Write the following function in C.

stripos — Find position of first occurrence of a case-
insensitive string
int stripos ( char* haystack, char* needle, int offset )

Returns the numeric position of the first occurrence of
needle in the haystack string. Note that the needle may be
a string of one or more characters. If needle is not found,
stripos() will return -1.

The function should not make use of any C library function
calls.

Answer Posted / anand

int stripos ( char* haystack, char* needle, int offset )
{
char *ptr;
ptr=haystack;
int pos=0;
while ( *ptr!='\0' )
{
if( *ptr == *needle )
return pos;
pos++;
ptr++;
}

return -1;
}

this function written for exact match of the charecter and
dosent bother for whatever is offset.

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how do you override a defined macro?

589


What are the advantages of c language?

667


What is null pointer constant?

596


What is else if ladder?

611


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3503






What is the use of function overloading in C?

680


What is the use of gets and puts?

605


Do you know the difference between exit() and _exit() function in c?

610


What is #define used for in c?

616


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

635


How was c created?

590


What are linker error?

615


What is the scope of an external variable in c?

570


What is the advantage of using #define to declare a constant?

624


What does dm mean sexually?

815