当前位置:网站首页>实现删除-一个字符串中的指定字母,如:字符串“abcd”,删除其中的”a”字母,剩余”bcd”,也可以传递多个需要删除的字符,传递”ab”也可以做到删除”ab”,剩余”cd”。
实现删除-一个字符串中的指定字母,如:字符串“abcd”,删除其中的”a”字母,剩余”bcd”,也可以传递多个需要删除的字符,传递”ab”也可以做到删除”ab”,剩余”cd”。
2022-08-02 00:06:00 【BSP初级小学僧】
分析:
本题思路较为简单,就是将要判断的字符串存入一个字符数组中,然后在该字符数组中一个元素一个元素的去判断,当某元素不等于要删除的元素时,将元素存入另一个字符数组中,以此循环。
代码:
/*
实现删除-一个字符串中的指定字母,如:字符串“abcd”,删除其中的”a”字母,剩余”bcd”,也可
以传递多个需要删除的字符,传递”ab”也可以做到删除”ab”,剩余”cd”。
*/
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100], str2[100],c;
int i = 0, j = 0;
printf("请输入原字符串:");
scanf("%s", str1);
getchar();
printf("请输入要删除的字母:");
scanf("%c", &c);
for (i = 0; i < strlen(str1);i++)
{
if (str1[i] != c)
{
str2[j] = str1[i];
j++;
}
}
str2[j] = '\0';
printf("删除后的字符串:%s", str2);
return 0;
}运行结果:

边栏推荐
- OpenCV DNN blogFromImage() detailed explanation
- 学习英语的网站与资料
- 利用“栈”快速计算——逆波兰表达式
- 基于注意力机制的多特征融合人脸活体检测
- [Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
- How to design a circular queue?Come and learn~
- JSP如何使用page指令让JSP文件支持中文编码呢?
- 22.支持向量机—高斯核函数
- 【HCIP】BGP小型实验(联邦,优化)
- [头条]笔试题——最小栈
猜你喜欢

bgp aggregation reflector federation experiment

Deliver cloud-native microservices applications with Zadig

REST会消失吗?事件驱动架构如何搭建?

测试用例:四步测试设计法

GetHashCode方法与=

Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation

一文概览最实用的 DeFi 工具

业务测试如何避免漏测 ?

如何优雅的消除系统重复代码

Don't know about SynchronousQueue?So ArrayBlockingQueue and LinkedBlockingQueue don't and don't know?
随机推荐
460. LFU cache
Quick solution for infix to suffix and prefix expressions
PHP从txt文件中读取数据的方法
632. 最小区间
How to get the best power efficiency in Windows 11?
链上治理为何如此重要,波卡Gov 2.0又会如何引领链上治理的发展?
TCL: Pin Constraints Using the tcl Scripting Language in Quartus
Task execution control in Ansible
What does the errorPage attribute of the JSP page directive do?
JSP out.write()方法具有什么功能呢?
基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
路由策略
JSP page指令errorPage属性起什么作用呢?
工业信息物理系统攻击检测增强模型
【21天学习挑战赛】顺序查找和二分查找的小总结
为什么要使用MQ消息中间件?这几个问题必须拿下
面试高频考题解法——栈的压入弹出序列、有效的括号、逆波兰表达式求值
How to design a circular queue?Come and learn~
JSP 如何获取request对象中的路径信息呢?
nodeJs--各种路径