Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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.

Answers were Sorted based on User's Feedback



Write the following function in C. stripos — Find position of first occurrence of a case- inse..

Answer / varun vithalani

I am working on the answer now but i can say that answer 1
and 2 are absolutely wrong. I haven't checked the 3rd yet.
In 1 and 2 solutions, it only looks for the first character
of the needle and does not care about the remaining.

For example:
haystack = "sweetsugar"
needle = "sugar"

It will return value '0' since it matches the first 's' of
'sweetsugar' and 'sugar'. The answer should be '5'.

Is This Answer Correct ?    3 Yes 1 No

Write the following function in C. stripos — Find position of first occurrence of a case- inse..

Answer / 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

Write the following function in C. stripos — Find position of first occurrence of a case- inse..

Answer / anand

int stripos ( char* haystack, char* needle, int offset )
{
char *ptr,X,Y;
int diff = 'A'-'a' ,pos=0;

ptr=haystack;
X=(*needle>='A' && *needls<='Z')?*needle-diff:*needle;
while ( *ptr!='\0' )
{ Y=(*ptr>='A' && *ptr<='Z')? *ptr-diff : *ptr )
if( Y == X )
return pos;
pos++;
ptr++;
}

return -1;
}

int offset is of no use in the function. however, the
question does not give any details of offset parameter. even
if provided the function may not require as all strings end
with NULL character ( same as '\0' ).

*needle is converted to small case letter and is compared
with converted small letter of the string.

Is This Answer Correct ?    0 Yes 0 No

Write the following function in C. stripos — Find position of first occurrence of a case- inse..

Answer / 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

More C Interview Questions

What is graph in c?

0 Answers  


what is pointer?

4 Answers  


is it possible to create your own header files?

0 Answers  


out put of printf(“%d”,printf(ram));

5 Answers  


Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates

3 Answers  


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

0 Answers   HP,


What is an volatile variable?

15 Answers   HP,


How can I manipulate strings of multibyte characters?

0 Answers  


write a program to display the numbers having digit 9 in the given range from 1 to 100

1 Answers  


Write a program to print distinct words in an input along with their count in input in decreasing order of their count..

1 Answers  


What is a macro in c preprocessor?

0 Answers  


What are the types of i/o functions?

0 Answers  


Categories