当前位置:网站首页>【指针】删除字符串s中的所有空格
【指针】删除字符串s中的所有空格
2022-07-06 09:24:00 【|光|】
要求
编一个函数,删除字符串s中的所有空格。(用指针实现)
代码
/* 该函数用来实现删除字符串中的所有空格 a为指向字符串数组的指针 */
char *delete_space(char *a)
{
int n = strlen(a);
int i=0,j=0,k=0;
char b[n];
for(i=0;i<n;i++)
{
if(a[i]==' ')
{
k++;
continue;
}
else
{
b[j]=a[i];
j++;
a[i]='\0';
}
}
for(j=0;j<n-k;j++)
{
a[j]=b[j];
}
return a;
}
main函数
int main()
{
char a[200];
gets(a);
delete_space(a);
puts(a);
return 0;
}
测试
测试输入
I A m A Student
输出
IAmAStudent
边栏推荐
猜你喜欢
Build domain environment (win)
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
Circular queue (C language)
Proceedingjoinpoint API use
Hackmyvm target series (2) -warrior
内网渗透之内网信息收集(一)
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
Detailed explanation of network foundation
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
Uibutton status exploration and customization
随机推荐
《统计学》第八版贾俊平第二章课后习题及答案总结
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
Detailed explanation of network foundation
记一次edu,SQL注入实战
Spot gold prices rose amid volatility, and the rise in U.S. prices is likely to become the key to the future
Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
JDBC read this article is enough
《统计学》第八版贾俊平第四章总结及课后习题答案
Intranet information collection of Intranet penetration (2)
Middleware vulnerability recurrence Apache
Hackmyvm target series (5) -warez
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
网络基础之路由详解
外网打点(信息收集)
“人生若只如初见”——RISC-V
Load balancing ribbon of microservices
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
7-7 7003 combination lock (PTA program design)