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
What are the difference between a free-standing and a hosted environment?
What are the different types of data structures in c?
Write a program to print "hello world" without using a semicolon?
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
How can a number be converted to a string?
Is c++ based on c?
What do you mean by keywords in c?
What are disadvantages of C language.
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
How can a process change an environment variable in its caller?
What is call by reference in functions?
Why is C language being considered a middle level language?
Write a code of a general series where the next element is the sum of last k terms.
Is it acceptable to declare/define a variable in a c header?
What is the role of this pointer?