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

#include<stdio.h>

int stripos(char* haystack, char* needle, int offset );

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

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

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

getch();
}

int stripos(char* haystack, char* needle, int offset )
{
char ch, *needle1;
int pos = 0, temp;

if(haystack != '\0' && needle != '\0')
{
while(*haystack != '\0')
{
needle1 = needle;
pos++;
temp = 0;
if((*haystack == *needle1) || (*haystack == *needle1 - 32)
|| (*haystack == *needle1 + 32))
{
offset = pos;
needle1++;
haystack++;
while(*needle1 != '\0')
{
if((*haystack == *needle1) || (*haystack ==
*needle1 - 32) || (*haystack == *needle1 + 32))
{
haystack++;
needle1++;
pos++;
}
else
{
temp = 1;
offset = -1;
break;
}
}
}
if(offset > 0)
{
return offset;
}

if(temp != 1)
haystack++;
}
}
return offset;
}

Is This Answer Correct ?    13 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Did c have any year 2000 problems?

1062


Which is best linux os?

971


How can you determine the size of an allocated portion of memory?

1238


Explain the difference between malloc() and calloc() in c?

1004


What is meant by inheritance?

1048


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

1010


Write a program for finding factorial of a number.

1032


Which header file is used for clrscr?

999


How can I find the modification date and time of a file?

1027


What’s the special use of UNIONS?

1106


Why string is used in c?

953


What is the significance of c program algorithms?

1098


What is a node in c?

918


How are pointers declared in c?

1006


What is scope rule of function in c?

1029