#if 1
void strndel(char src[], int size, char del[], int s2)
{
int i, j, k;
for (i = 0; i < size; i++)
{
for (k = 0; k <= s2; k++)
{
if (src[i] == del[k])
{
for (j = i; j <= size + 1; j++)
{
src[j] = src[j + 1];
}
}
}
}
}
#endif
#if 1
void strdel(char src[], int size, char del)
{
int i, j;
for (i = size; i >= 0; i--)
{
if (src[i] == del)
{
for (j = i; j < size + 1; j++)
{
src[j] = src[j + 1];
}
}
}
}
#endif
主函数
char a[] = "they are my baby";
char b = 'e';
char c[] = "bc";
int i = sizeof(a);
int j = sizeof(c);
strdel(a, i, b);
printf("%s\n", a);
strndel(a, i, c, j);
printf("%s\n", a);
但是我不明白为什么会这样
samba@ubuntu64:~/share$ gcc test.c
samba@ubuntu64:~/share$ ./a.out
hello world!
17
thy ar my baby
hy ar my ay刈
samba@ubuntu64:~/share$ gcc test.c
samba@ubuntu64:~/share$ ./a.out
hello world!
17
thy ar my baby
hy ar my ayzzzzzzz¾
samba@ubuntu64:~/share$ gcc test.c
samba@ubuntu64:~/share$ ./a.out
hello world!
17
thy ar my baby
hy ar my ay$GGGGGGG¡ÿ
samba@ubuntu64:~/share$ gcc test.c
samba@ubuntu64:~/share$ ./a.out
hello world!
17
thy ar my baby
hy ar my aya¤¤¤¤¤þ
samba@ubuntu64:~/share$