当前位置:网站首页>Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can
Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can
2022-08-02 00:33:00 【BSP Junior Primary School Monk】
Analysis:
The idea of this question is relatively simple, that is, store the string to be judged in a character array, and then judge one element by one in the character array. When an element is not equal to the element to be deleted, store the element inAnother character array, and so on.
Code:
/*Realize deletion - a specified letter in a string, such as: string "abcd", delete the "a" letter in it, the remaining "bcd", orIn order to pass multiple characters that need to be deleted, passing "ab" can also delete "ab" and leave "cd".*/#include#includeint main(){char str1[100], str2[100],c;int i = 0, j = 0;printf("Please enter the original string: ");scanf("%s", str1);getchar();printf("Please enter the letter to delete: ");scanf("%c", &c);for (i = 0; i < strlen(str1); i++){if (str1[i] != c){str2[j] = str1[i];j++;}}str2[j] = '\0';printf("Deleted string: %s", str2);return 0;} Run result:

边栏推荐
猜你喜欢

Arduino Basic Syntax

These 4 computer notepad software, you have to try

BGP 第一次实验

TCL:在Quartus中使用tcl脚本语言进行管脚约束

测试点等同于测试用例吗

When Netflix's NFTs Forget Web2 Business Security

Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)

辨析内存函数memset、memcmp、memmove以及memcpy

IP核:FIFO

中缀转后缀、前缀表达式快速解决办法
随机推荐
Short video seo search optimization main content
磁盘与文件系统管理
poker question
06-SDRAM : SDRAM control module
JSP如何使用page指令让JSP文件支持中文编码呢?
Disk and file system management
当奈飞的NFT忘记了Web2的业务安全
Short video SEO optimization tutorial Self-media SEO optimization skills and methods
PHP to read data from TXT file
测试用例:四步测试设计法
uni-app project summary
els 长条变形
Knowing the inorder traversal of the array and the preorder traversal of the array, return the postorder history array
After reshipment tencent greetings to monitor if the corresponding service does not exist by sc. Exe command to add services
[HCIP] BGP Small Experiment (Federation, Optimization)
Play NFT summer: this collection of tools is worth collecting
回顾历史5次经济衰退时期:这一次可能会有何不同?
玩转NFT夏季:这份工具宝典值得收藏
JSP built-in object out object function introduction
How does JSP use the page command to make the JSP file support Chinese encoding?