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 kanawally

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;
}

Is This Answer Correct ?    4 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the valid places to have keyword “break”?

647


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2602


how is the examination pattern?

1594


Why & is used in scanf in c?

616


Explain what is the general form of a c program?

618






How many levels deep can include files be nested?

646


7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.

2215


diff between exptected result and requirement?

1592


What is time null in c?

579


can we implement multi-threads in c.

657


When can you use a pointer with a function?

560


How do I read the arrow keys? What about function keys?

610


write a program to create a sparse matrix using dynamic memory allocation.

4370


Explain what is dynamic data structure?

642


Write a program to print "hello world" without using a semicolon?

590