C语言:有一行文字,要求删去其中某个字符。此行文字和要删除的字符均由键盘输入。

来源:百度知道 编辑:UC知道 时间:2024/06/14 07:36:59

#include<stdio.h>
#include<string.h>

char s[10000];
char c;

int main()
{
printf("Input the original string:\n");
gets(s);
printf("The original string is: %s\n",s);
printf("Input the char should be deleted:\n");
scanf("%c",&c);
printf("The char should be deleted is %c\n",c);
for(int i=0;s[i];i++)
if(s[i]==c)
{
memmove(s+i,s+i+1,strlen(s+i+1)+1);
break;
}
printf("The string after delete operation is: %s\n",s);
return 0;
}