-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_substring.c
More file actions
39 lines (36 loc) · 753 Bytes
/
Copy pathfind_substring.c
File metadata and controls
39 lines (36 loc) · 753 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
// finding substring in a given string
#include <stdio.h>
void main()
{
char str[200],s[50];
int index;
system("cls");
printf(" =====finding substring in string====\n ");
printf("\n Enter string ");
gets(str);
printf("\n Enter substring ");
gets(s);
index = index_of_substr(str,s);
if(index== -1){
printf("string not found\n ");
}
else{
printf("string found at index %d\n ",index);
}
}
int index_of_substr(char str[],char s[])
{
int i,j,k,l;
l= strlen(s);
for(i=-0;str[i+l-1];i++){
k=i;
for(j=0;j<=l-1;j++){
if(str[k] !=s[j])
break;
k++;
}
if(j==l)
return (i);
}
return (-1);
}