在一行文字中,删除其中某个字符,此行文字和需要删除的字符均由键盘输入

2025-04-18 03:31:11
推荐回答(2个)
回答1:

#include
#include
void main()
{char line[80] ;
char ch;
int i,j;
int len;
printf("输入一行字符 \n");
//___________________ ;
gets(line);
printf("输入要删除字符 ");

ch=getchar();
i=0;
while(line[i]!='\0' )
{// while(__________________&& line[i]!=ch) i++;
while(line[i]!='\0'&& line[i]!=ch) i++;
len=strlen(line);
for(j=i;j // __________________;
line[j]=line[j+1];
line[j]='\0';
}
puts(line);
}

回答2:

//写好了,对不起,没看到楼上已经回答了
#include
#include
void main()
{char line[80] ;
char ch;
int i,j;
int len;
printf("输入一行字符 \n");
//___________________ ;
gets(line);
printf("输入要删除字符\n ");
ch=getchar();
i=0;
while(line[i]!='\0' )
{
while(line[i]!='\0'&& line[i]!=ch) i++;//
len=strlen(line);
for(j=i;j line[j]=line[j+1];
line[j]='\0';
}
puts(line);
}