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
Do you know what are the properties of union in c?
What is the difference between NULL and NUL?
What does volatile do?
What are the types of i/o functions?
What is the difference between a free-standing and a hosted environment?
What is a global variable in c?
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
What the advantages of using Unions?
Why is sizeof () an operator and not a function?
How are variables declared in c?
Explain what is wrong with this program statement? Void = 10;
What is the use of clrscr?
Why is python slower than c?
What is pass by reference in functions?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant