直接上代码
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <assert.h>
int delete_char(const char * str, const char * sub_str, char * result)
{
assert( str != NULL && sub_str != NULL);
int i,j;
int k = 0;
int count = 0;
char *p = result;
for (i = 0 ; str[i] != '\0'; i++)
{
int temp = i;
j = 0;
while(str[i] != NULL && sub_str[j] != NULL && str[i] == sub_str[j])
{
i++;
j++;
}
if (sub_str[j] != '\0')
{
i = temp;
p[k] = str[i];
k++;
}
else
{
count += 1;
i--;
}
}
p[k]='\0';
return count;
}
int main()
{
char a[] = "hello1234he123llo";
char b[] = "8";
char c[sizeof(a) - 1] = "";
printf("%d\n",delete_char(a, b, c));
printf("%s\n",c);
return 0;
}