当前位置:网站首页>指针--剔除字符串中的所有数字
指针--剔除字符串中的所有数字
2022-07-06 09:24:00 【|光|】
要求
编一个函数,剔除字符串中的所有数字。(用指针实现)
代码
#include<stdio.h>
/* * 该函数用来实现删除字符串中的所有数字 *a为指向字符串数组的指针 */
char *delete_digit(char *a)
{
int l = strlen(a);
char b[l];
int i,j=0,k;
for(i=0;i<l;i++)
{
if(a[i]>='0'&&a[i]<='9')
continue;
else
{
b[j] = a[i];
j++;
}
}
for(i=0;i<l;i++)
{
a[i] = '\0';
}
for(i=0;i<l-2;i++)
{
if(b[i]=='.')
{
if(b[i+2]>='a'&&b[i+2]<='z')
continue;
else if(b[i+2]>='A'&&b[i+2]<='Z')
continue;
else
b[i+1]='\0';
}
}
strcpy(a,b);
return a;
}
main函数
int main()
{
char a[200];
gets(a);
delete_digit(a);
puts(a);
return 0;
}
测试
测试输入
123Try234 you53r b5234est wh2435en y25ou2 are 5234young. 45324Never524 regret523.
输出
Try your best when you are young. Never regret.
边栏推荐
- 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
- XSS (cross site scripting attack) for security interview
- 数据库多表链接的查询方式
- List and data frame of R language experiment III
- Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
- Hackmyvm target series (7) -tron
- 1.支付系统
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- 攻防世界MISC练习区(gif 掀桌子 ext3 )
- MSF generate payload Encyclopedia
猜你喜欢
Low income from doing we media? 90% of people make mistakes in these three points
Harmonyos JS demo application development
Hcip -- MPLS experiment
Detailed explanation of network foundation
Only 40% of the articles are original? Here comes the modification method
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
中间件漏洞复现—apache
JDBC事务、批处理以及连接池(超详细)
Hackmyvm target series (2) -warrior
Ucos-iii learning records (11) - task management
随机推荐
网络层—简单的arp断网
List and data frame of R language experiment III
图书管理系统
内网渗透之内网信息收集(五)
Xray and Burp linked Mining
MSF generate payload Encyclopedia
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
JDBC transactions, batch processing, and connection pooling (super detailed)
Build domain environment (win)
JVM memory model concept
How to understand the difference between technical thinking and business thinking in Bi?
JDBC看这篇就够了
关于超星脚本出现乱码问题
New version of postman flows [introductory teaching chapter 01 send request]
Intranet information collection of Intranet penetration (I)
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
Record an edu, SQL injection practice
Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
Middleware vulnerability recurrence Apache
Mathematical modeling idea of 2022 central China Cup