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

Do you know what are the properties of union in c?

587


What is the difference between NULL and NUL?

729


What does volatile do?

568


What are the types of i/o functions?

684


What is the difference between a free-standing and a hosted environment?

643






What is a global variable in c?

591


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

626


What the advantages of using Unions?

674


Why is sizeof () an operator and not a function?

591


How are variables declared in c?

600


Explain what is wrong with this program statement? Void = 10;

766


What is the use of clrscr?

598


Why is python slower than c?

608


What is pass by reference in functions?

326


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

670