1.数组
#include<stdio.h>
void lake(char a[], char b[], char c)
{
int i, j;
for(i=0,j=0;a[i]!='\0';i++) //易错a[i]!='\0'
if (a[i] != c)
{
b[j] = a[i];
j++;
}
b[j] = '\0';
}
int main()
{
char a[66], b[66], c;
gets_s(a);
scanf_s("%c", &c);
lake(a, b, c);
puts(b);
return 0;
}
%s对应数组名;
2.指针
#include<stdio.h>
#include<stdlib.h>
void lake(char *p1, char *p2, char c)
{
for (; *p1 != '\0'; p1++)
{
if (*p1 != c)
{
*p2 = *p1;
p2++;
}
}
*p2 = '\0';
}
int main()
{
char a[66], b[66], c;
printf("输入字符\n");
gets_s(a); //数组输入用gets_s
printf("输入删除字符\n");
scanf_s("%c",&c);
lake(a, b,c);
printf("%s", b);
system("pause");
return 0;
}