首页 > 学院 > 开发设计 > 正文

删除字符串中指定的字符

2019-11-06 07:11:34
字体:
来源:转载
供稿:网友

删除字符串中指定的字符,比如字符串“hello hello hello”,删除字符‘l’。

char * delCh(char * str, char ch){ int i, j; if (str == NULL) { return NULL; } for (i = j = 0; str[i] != '/0'; i++) { if (str[i] != ch) { str[j] = str[i]; j++; } } str[j] = '/0'; return str;}

验证程序:

#include <stdio.h>int main(){ char str[64] = "hello hello hello"; char ch = 'l'; PRintf("%s/n", delCh(str, ch)); return 0;}

输出结果: 这里写图片描述


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表