forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.2.c
executable file
·56 lines (41 loc) · 1.08 KB
/
6.2.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
#include <stdio.h>
#include <string.h>
#include <assert.h>
int del_substr(char *str, char *substr);
int find_str(char *str, char *substr);
int main()
{
char *str = "ABCDEFGHIJK";
char *substr = "DBCD";
printf("%d", find_str(str, substr));
if (! find_str(str, substr)) {
printf("not exists substr in str\r\n");
return 0;
}
}
int find_str(char *str, char *substr)
{
int counter = 0;
assert(str != NULL);
if (substr == NULL) {
return 1;
}
while (*str != '\0') {
char str_char = *str;
char substr_char = *substr;
if (str_char == substr_char) {
while (1) {
str_char = *++str;
substr_char = *++substr;
if (str_char != substr_char && substr_char != '\0') {
break;
}
if ((str_char != substr_char && substr_char == '\0') || (str_char == substr_char && substr_char == '\0')) {
return 1;
}
}
}
str++;
}
return 0;
}