|
Get 9,000+ Interview Questions with Answers in an eBook
C Source Codes List | Source Code Home
Program : Program to find out the rightmost occurence of an i/p character in an i/p string.
/* Prg. to find out the rightmost occurence of an i/p character in an i/p
string. */
#include
#include
int strindex(char s[],char t);
void main()
{
char s[80],t;
int a=0;
clrscr();
printf("\nEnter main string(i.e. s):-\n");
gets(s);
printf("\nEnter the character to be searched(i.e. t):- ");
t=getchar();
a=strindex(s,t);
if (a>=0)
printf("\n\nThe required character is found at position %d.",a);
else
printf("\n\nThe required character is not found in the string.");
getch();
}
int strindex(char s[],char t)
{
int i=0;
for (i=strlen(s);i>=0;i--)
{
if (s[i]==t)
return(i);
}
if (i<0)
return(-1);
}
C Source Codes List | Source Code Home
|
|
|