-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_substring.c
More file actions
52 lines (52 loc) · 815 Bytes
/
find_substring.c
File metadata and controls
52 lines (52 loc) · 815 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
46
47
48
49
50
51
52
#include<stdio.h>
#include<string.h>
main()
{
int a,len_sub,len_main;
char main[100];
char sub[100];
scanf("%s",main);
scanf("%s",sub);
len_sub=strlen(sub);
//len_main=strlen(main);
//printf("%d",len_main);
a=check_present(main,sub);
if(a==len_sub)
{
printf("substring is present \n");
}
else
{
printf("substring is not present \n");
}
}
int check_present(char* main,char* sub)
{
int count=0;
char prev;
while(*sub!='\0')
{
while(*main!='\0')
{
if(*sub==*main)
{
prev=*main;
main++;
count++;
printf("%d",count);
break;
}
else
main++;
}
sub++;
//char next=*main++;
printf("%c",*main);
printf("%c",prev);
//printf("%c",next);
if(*main!=*sub && *sub!='\0' && prev!=*main)
return 0;
}
printf(" outside while %d",count);
return count;
}