-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path字符串中的删除
68 lines (57 loc) · 1.27 KB
/
字符串中的删除
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
//
// main.c
// assignment problem 1.2
//
// Created by 毛遵杰 on 2019/9/29.
// Copyright © 2019 毛遵杰. All rights reserved.
//
#include <stdio.h>
int del_substr(char *str,char const*substr)
{
int i,j,k,flag,t;
for (i=0;str[i] != '\0'; i++)
{
j=0;
flag=0;
if (str[i] == substr[j])
{
k=i;
for (j=0; str[k] != '\0' && substr[j]!='\0'; k++,j++)
{
if (str[k] != substr[j])
{
flag=1;
break;
}
}
if ( substr[j] =='\0' && flag == 0)
{
for (t=0;t<j;t++)
{
for (k=i;str[k+1]!='\0';k++)
{
str[k]=str[k+1];
}
str[k]='\0';
}
str[k]='\0';
return 1;
}
}
}
return 0;
}
int main()
{
char s1[100]={0};// "ABCDEFG"
char s2[50]={0};
while(1){
printf("please enter string 1");
scanf("%s",s1);
printf(" please enter string 2");
scanf("%s",s2);
del_substr(s1,s2);
printf("%s\n",s1);
}
return 0;
}