forked from Suxyuuu/buaa-991
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2014.c
48 lines (42 loc) · 941 Bytes
/
2014.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
// 求某个长字符串中指定字符串出现的频率 要求所有的字符串操作用指针完成!
#include <stdio.h>
#include <string.h>
#define MAXSIZE 100
int STRCOUNT(char* source, char* destination);
int main(void){
char source[MAXSIZE]="accdefgdefkdxefaaaa";
char destination[MAXSIZE]="def";
char * s=source, * d=destination;
printf("%d\n",STRCOUNT(s, d));
getchar();
return 0;
}
int STRCOUNT(char* source, char* destination){
int count=0;
char * s=source;
char * d=destination;
char * pos=source;
while (*s)
{
//pos=s;
if (*s == * d)
{
s++;
d++;
}
else if (*d == '\0')
{
count++;
pos++;
s=pos;
d=destination;
}
else
{
pos++;
s=pos;
d=destination;
}
}
return count;
}