C语言编程题答案,急求

来源:百度知道 编辑:UC知道 时间:2024/04/28 16:46:14
请使用指针编程实现:将字符串中指定的字符删除,然后输出剩余字符串。如字符串为“abcaca”,删除字符为“a”,结果为“bcc”。

#include <stdio.h>
int main()
{
char str[50],tmp[50];
char ch;
int i,j;

printf("请输入原字符串:");
scanf("%s",str);
fflush(stdin);
printf("请输入要删除的字符:");
scanf("%c",&ch);

for(i=0,j=0;str[i]!='\0';i++)
{
if(str[i]!=ch)
{
tmp[j++]=str[i];
}
}
tmp[j]='\0';

printf("删除字符%c后的字符串为:%s\n",ch,tmp);
return 0;
}

楼下的两位仁兄可真有意思啊,特别是这位总监大人...

#include <stdio.h>
int main()
{
char str[50],tmp[50];
char ch;
int i,j;
scanf("%s",str);//输入原字符串
fflush(stdin);
scanf("%c",&ch);//要删除的字符
for ( i=0,j=0;str[i]!='\0';i++)
{
if (str[i]!=ch)
{
tmp[j++]=str[i];
}
}
tmp[j]='\0';
printf("%s\n",tmp);//输出结果
return 0;