1.字符数组
#include <stdio.h>
#include <string.h>
void BB(char a[20],char N)
{
int i,k;
for(i=0;a[i]!='\0';i++)
{
if(a[i]==N)
{
for(k=i;a[k]!='\0';k++)
a[k]=a[k+1];
i--;
}
}
}
void main ()
{
char a[20],N;
printf("输入一个字符串:");
gets(a);
printf("请输入要删除的字符:");
scanf("%c",&N);
BB(a,N);
puts(a);
}
2.字符指针
#include <stdio.h>
#include <string.h>
void BB(char *p,char N)
{
int i,k;
char *q;
for(;*p!='\0';p++)
{
if(*p==N)
{
for(q=p;*q!='\0';q++)
*q=*(q+1);
p--;
}
}
}
void main ()
{
char a[20],N;
char *p = a;
printf("输入一个字符串:");
gets(p);
printf("请输入要删除的字符:");
scanf("%c",&N);
BB(p,N);
puts(p);
}
追问第二个呢!
追答#include
#include
void BB(char *p,char N)
{
int i,k;
char *q;
for(;*p!='\0';p++)
{
if(*p==N)
{
for(q=p;*q!='\0';q++)
*q=*(q+1);
p--;
}
}
}
void main ()
{
char a[20],N;
char *p = a;
printf("输入一个字符串:");
gets(p);
printf("请输入要删除的字符:");
scanf("%c",&N);
BB(p,N);
puts(p);
}
追问这是什么方法?
我C语言渣得很!看不懂!
追答就是删除字符串中与某个相同的字符啊,第一个用的数组,第二个用的指针啊
本回答被提问者采纳