-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstring_1.c
93 lines (88 loc) · 1.36 KB
/
string_1.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <string.h>
int cspn(char s1[], char s2[]);
int spn(char s1[], char s2[]);
char *rchr(char str[], char c);
char *chr(char str[], char c);
char *str(char str[], char sub[])
{
int i = 0, j;
while (sub[i] != '\0')
{
j = 0;
while (str[j] != '\0')
{
if ((sub[i] == str[j]) && (str[j + 1] == sub[i + 1]))
return &str[j];
j++;
}
i++;
}
return NULL;
}
int main(void)
{
char *p;
int n;
p = chr("kumar shanu", 'm');
printf("%s\n", p);
n = cspn("honor 9 lite", "akj");
printf("%d\n", n);
p = str("honor on lite", "hello");
printf("%s\n", p);
}
char *chr(char str[], char c)
{
int i = 0;
while (str[i] != '\0')
{
if (str[i] == c)
return &str[i];
i++;
}
return NULL;
}
char *rchr(char str[], char c)
{
int i, l;
l = strlen(str);
for (i = l - 1; i >= 0; i--)
{
if (str[i] == c)
return &str[i];
}
return NULL;
}
int spn(char s1[], char s2[])
{
int i = 0, j = 0, count = 0;
while (s2[i] != '\0')
{
j = 0;
while (s1[j] != '\0')
{
if (s1[j] == s2[i])
count++;
j++;
}
i++;
}
return count;
}
int cspn(char s1[], char s2[])
{
int i = 0, j, count = 0;
while (s1[i] != '\0')
{
j = 0;
while (s2[j] != '\0')
{
if (s1[i] == s2[j])
return count;
j++;
}
i++;
count++;
}
return count;
}