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.

Answer Posted / amaresh

#include<stdio.h>
int stripos(char* haystack, char* needle, int offset );

void main()
{
char *a1, *a2;
int iPostn = 0;
printf("ENTER THE HAYSTACK STRING:\n");
gets(a1);
printf("\nENTER THE STRING - TO BE SEARCHED\n");
gets(a2);
iPostn = stripos(a1, a2, iPostn);

if(iPostn > 0)
printf("\nSTRING STARTS AT THE POSITION:
%d\n", iPostn);

else
printf("\nSTRING NOT FOUND: %d\n", iPostn);
printf("\n");
}

int is_match(char a, char b)
{
char c1, c2;
if( a >= 'A' && a <= 'Z')
c1 = a + 32;
else
c1 = a;

if( b >= 'A' && b <= 'Z')
c2 = b + 32;
else
c2 = b;

if(c1 == c2)
return 1;
else
return 0;
}

int stripos( char* haystack, char* needle, int offset )
{
int i = 0, j = 0, pos = -1;

if(*haystack == '\0' || *needle == '\0')
return -1;

while(haystack[i + j] != '\0')
{
if(is_match(haystack[i + j],needle[j]))
{
pos = i + 1;
j++;
}
else
{
i++;
pos = -1;
j = 0;
}
if(needle[j] == '\0')
return pos;
}
return -1;
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you construct an increment statement or decrement statement in C?

1176


What does %2f mean in c?

1160


What is bss in c?

1044


Explain what header files do I need in order to define the standard library functions I use?

1114


Sir i need notes for structure,functions,pointers in c language can you help me please

2349


What is substring in c?

1132


What are structures and unions? State differencves between them.

1099


What is the right type to use for boolean values in c? Is there a standard type?

966


How does free() know explain how much memory to release?

1012


What is indirection?

1023


the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b

2614


What is assert and when would I use it?

963


What is array in C

1099


What is actual argument?

1005


What is boolean in c?

1032