C > Beginners Lab Assignments
Program to find out the rightmost occurence of an input character
Program to find out the rightmost occurence of an input character in an input string #include
#include
int strindex(char s[],char t); void main() { char s[80],t; int a=0; clrscr(); printf(" Enter main string(i.e. s):- "); gets(s); printf(" Enter the character to be searched(i.e. t):- "); t=getchar(); a=strindex(s,t); if (a>=0) printf(" The required character is found at position %d.",a); else printf(" The 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 Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting