0
sahems87's Avatar, Join Date: Jun 2010
Newbie Member
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.

is this code correct or not????

void main()
{
//char str[20]="Your String Goes Here";
char str[50];
int chr,i,chr2,flag=0;
//Or Use This Da
printf("Enter The String");
scanf("%s",str);
printf("Enter The Character To Find");
scanf("%d",&chr);
if(chr>=90)
{
chr2=chr-32;
}
else
{
chr2=chr+32;
}
for(i=0;i<20;i++)
{
if((chr==(int)str[i])||(chr2==(int)str[i]))
{
break;
flag=1;
}
}
if(flag==1)
{
printf("Character Found At position %d ",i-1);
}
else
{
printf("Character Not Found");
}
}
0
sahems87's Avatar, Join Date: Jun 2010
Newbie Member
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.

is this correct or not??


void main()
{
//char str[20]="Your String Goes Here";
char str[50];
int chr,i,chr2,flag=0;
//Or Use This Da
printf("Enter The String");
scanf("%s",str);
printf("Enter The Character To Find");
scanf("%d",&chr);
if(chr>=90)
{
chr2=chr-32;
}
else
{
chr2=chr+32;
}
for(i=0;i<20;i++)
{
if((chr==(int)str[i])||(chr2==(int)str[i]))
{
break;
flag=1;
}
}
if(flag==1)
{
printf("Character Found At position %d ",i-1);
}
else
{
printf("Character Not Found");
}
}
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Please use code tags when posting code. It's right there in the posting guidelines.

Why do you need to ask if it's correct?
Does it work as you expect? If not then how can it be correct? If it does then how can it not be correct? (OK it might not be optimal, but if it works then that's often good enough)