-
Notifications
You must be signed in to change notification settings - Fork 0
/
string-p.c
58 lines (51 loc) · 1.22 KB
/
string-p.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
#include <stdio.h>
#include <stdlib.h>
#define NUL '\0'
#define FALSE 0
#define TRUE 1
int strlen(char *str)
{
int length = 0;
while(*str++ != '\0')
{
length += 1;
}
return length;
}
char *match(char *str, char *want)
{
while(*want != NUL)
if(*str++ != *want++)
return NULL;
return str;
}
int del_substr(char *str, char const *substr)
{
char *next;
while(*str != NUL)
{
next = match(str, substr);
if(next != NULL)
break;
str++;
}
if(*str == NUL)
return FALSE;
while(*str++ = *next++)
;
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("============ Usage ============\n./bouli \"liboshi\" \"bo\"\n");
exit(1);
}
char *name = "liboshi";
int len = strlen(name);
printf("The length of string %s is: %d\n", name, len);
del_substr(argv[1], argv[2]);
printf("The string is: %s\n", argv[1]);
printf("Args number is: %d", argc);
}