当前位置:网站首页>【指针】删除字符串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
边栏推荐
猜你喜欢

JDBC read this article is enough

关于超星脚本出现乱码问题

Record once, modify password logic vulnerability actual combat

Web vulnerability - File Inclusion Vulnerability of file operation

Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class

攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)

循环队列(C语言)

《統計學》第八版賈俊平第七章知識點總結及課後習題答案

Chain team implementation (C language)

Tencent map circle
随机推荐
内网渗透之内网信息收集(三)
XSS (cross site scripting attack) for security interview
How to understand the difference between technical thinking and business thinking in Bi?
JVM memory model concept
Realize applet payment function with applet cloud development (including source code)
New version of postman flows [introductory teaching chapter 01 send request]
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
《统计学》第八版贾俊平第三章课后习题及答案总结
Lintcode logo queries the two nearest saplings
搭建域环境(win)
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
Solutions to common problems in database development such as MySQL
网络基础之路由详解
《统计学》第八版贾俊平第五章概率与概率分布
AQS details
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
Chain team implementation (C language)
2022华中杯数学建模思路
Data mining - a discussion on sample imbalance in classification problems