当前位置:网站首页>【指针】删除字符串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
边栏推荐
- WEB漏洞-文件操作之文件包含漏洞
- 内网渗透之内网信息收集(四)
- Constants, variables, and operators of SystemVerilog usage
- Which is more advantageous in short-term or long-term spot gold investment?
- 内网渗透之内网信息收集(一)
- Network technology related topics
- Lintcode logo queries the two nearest saplings
- How to turn wechat applet into uniapp
- 《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
猜你喜欢
随机推荐
captcha-killer验证码识别插件
搭建域环境(win)
【指针】查找最大的字符串
Build domain environment (win)
How to test whether an object is a proxy- How to test if an object is a Proxy?
《统计学》第八版贾俊平第二章课后习题及答案总结
Record once, modify password logic vulnerability actual combat
Internet Management (Information Collection)
Data mining - a discussion on sample imbalance in classification problems
xray與burp聯動 挖掘
Harmonyos JS demo application development
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
C language file operation
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
Hackmyvm target series (3) -visions
Ucos-iii learning records (11) - task management
内网渗透之内网信息收集(一)
内网渗透之内网信息收集(三)
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence







