C函数从字符串中删除一个字符的实例



我做得对,但它只适用于基本字符串是一个单词:# include & lt; stdio.h>

void withoutString(char *new, char *base, char removee){
while(*base){
if(*base!=removee){
*new++=*base;}
base++;


}
*new='';
}
int main()
{
char b[16],n[16],r;
printf("Please enter string: ");
scanf(" %s", b);
printf("Which character do you want to remove? n");
scanf(" %c",&r);                       
withoutString(n, b, r);                       
printf(" The new string is %s", n);
return 0;
}

我如何使它工作更多的单词?

阅读并理解scanf的文档。C标准函数文档的良好来源是C标准本身和POSIX。

您将注意到scanf不是读取整行的最佳函数,所以接下来寻找fgets

最新更新