Monday 6 January 2014

C PROGRAM TO DEVELOP STRING FUNCTION -- strrchr

#include<stdio.h>
#include<string.h>
#include<conio.h>

char *my_strrchr(char *string,char charecter);

int main()
{
    char str[20];
    char ch;
    char *dest;
   
    printf("enter any string:");
    gets(str);
   
    printf("enter an charecter to search in the string:");
    scanf("%c",&ch);
   
    dest=my_strrchr(str,ch);
   
    printf("\n dest=%s",dest);
   
    getch();
    return 0;
}


char *my_strrchr(char *string,char charecter)
{
     char *temp;
     int flag=0;
     while(*string!='\0')
     {
                         if(*string==charecter)
                         temp=string;flag=1;
                        
                         string++;
                         }
                        
                         if(flag==1)
                         return(temp);
                         else
                         return(NULL);
                         }

No comments:

Post a Comment