forked from Vishal-Aggarwal0305/DSA-CODE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFirst.c
More file actions
46 lines (37 loc) · 778 Bytes
/
StringFirst.c
File metadata and controls
46 lines (37 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <string.h>
int main()
{
char a[50],ch,*p=a;
int len=0,flag=0,i;
printf("Enter the string\n");
gets(a);
printf("Enter the character u want to search\n");
scanf("%c",&ch);
while(a[len]!='\0')
{
len++;
}
//printf("%d",len);
//finding first occurence
for(i=len-1;i>=0;i--)
{
if(a[i]==ch)
{
flag++;
break;
}
}
p+=i;
if (flag==0)
{
printf("Character not found");
}
else
{
printf("Rear end with %c is %s",ch,p);
}
printf("\nBy using Pre Defined Function:\n");
char *index=strrchr(a,ch);
printf( "The rear occurrence of %c in '%s' is '%s'\n",ch,a,index );
}