'i++) if(str[i]==ch"og:type" content="webpage">'i++) if(str[i]==ch" /> 'i++) if(str[i]==ch"> 编制函数fun,其功能是:删除一个字符串中指定的字符。_系统运维_内存溢出

阅读 9

编制函数fun,其功能是:删除一个字符串中指定的字符。,第1张

#include <stdio.h>void fun(char str[],char ch){ int i,j for(i=0str[i]!='\0'i++) if(str[i]==ch){for(j=istr[j]!='\0'j++) str[j]=str[j+1] }}int main(){ char str[100],ch printf("enter a string :") // 不需要提示语的话删去此行 gets(str) printf("enter you want delete letter : ")// 不需要提示语的话删去此行 ch=getchar() fun(str,ch) printf("%s\n",str)return 0}利用C语言删除字符串

中所有指定的字符方法如下: 1.基本方法是,编写函数

fun:deletechar()。这个函数需要接受两个参数的传入,一个为该字符串str,另一个为想删除的字符c。通过对整个字符串的逐个遍历,凡是检测到字符为c,则删除此字符。具体实现代码如下:

2.在主函数,只需要接受用户输入的字符串,然后调用deletechar()函数,最后输出结果即可。主函数代码实现部分如下:

扩展资料:

1.remove()是C语言中的函数,一般作用是删除数组、链表对象所有的元素。函数原型是

2.remove()函数用于删除指定的文件,其原型如下:

参考资料:remove()函数-百度百科

char delch(char str[],char c){

char *s = str

for(int i=0str[i]!='\0'i++){

if(str[i]!=c){

*s = str[i]

s++

}

}

*s = '\0'

return c


}

欢迎分享,转载请注明来源:

内存溢出

原文地址:

https://outofmemory.cn/yw/9022973.html
删去
(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
给虚拟机中的Linux系统设置静态IP
上一篇
2023-04-24
本地传文件到linux服务器报connectionreset
2023-04-24

发表评论
请登录后评论... 登录
提交

    评论列表(0条)
保存
{label} {label}