forked from srinirad/Test3Session2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp6final.c
More file actions
32 lines (27 loc) · 674 Bytes
/
p6final.c
File metadata and controls
32 lines (27 loc) · 674 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
/* Write a program to find the index of a substring of a string.
void input_string(char *a);
int str_reverse(char *string, char *substring);
void output(char *string, char *substring, int index); */
int string_length(char *s)
{
int i;
for(i=0;s[i]!='\0';i++);
return i;
}
int string_ncmp(char *s1,char *s2)
{
for(int i=0; i<n && s1[i]==s2[i] && s1[i] != '\0';i++);
return s1[i] - s2[i];
}
int string_index(char *s, char *subs)
{
int l1=string_lenght(s);
int l2=string_lenght(subs);
if l1 < l2
return -1;
for(int i=0;i<l1-l2;i++)
if (string_nscmp(s,subs))
return i;
return -1;
}
/* Understand and debug the functions and write main */