4.30 删除字符串中的空格
来源:互联网 发布:数据透视表 实例教程 编辑:程序博客网 时间:2024/06/03 05:03
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char str[50];
char str_2[50];
//用数组实现
char delete_space(char a[50])
{
char temp[50];
int i = 0;
int j = 0;
while(a[i] != '\0')
{
// printf("*\n");
if(a[i] != ' ')
{
temp[j] = a[i];
i++;
j++;
// a++;
// temp++;
}
else if(a[i] == ' ')
{
i++;
}
}
temp[j] = '\0';
printf("%s\n",temp);
return 0;
}
char delete_space_by_printor(char *b)
{
char *p,*q;
for(p=b;*p!='\0';p++)
{
q=p;
if(*q==' ')
{
while(*q != '\0')
{
*q = *(q+1);
q++;
}
}
}
printf("%s\n",b);
return 0;
}
void main()
{
// char str[50];
// fflush();
printf("please input a string\n");
gets(str);
printf("after delete space:\n");
delete_space(str);
printf("please input a string 2:\n");
gets(str_2);
printf("after delete space_str_2:\n");
delete_space_by_printor(str_2);
}
#include <string.h>
#include <stdlib.h>
char str[50];
char str_2[50];
//用数组实现
char delete_space(char a[50])
{
char temp[50];
int i = 0;
int j = 0;
while(a[i] != '\0')
{
// printf("*\n");
if(a[i] != ' ')
{
temp[j] = a[i];
i++;
j++;
// a++;
// temp++;
}
else if(a[i] == ' ')
{
i++;
}
}
temp[j] = '\0';
printf("%s\n",temp);
return 0;
}
char delete_space_by_printor(char *b)
{
char *p,*q;
for(p=b;*p!='\0';p++)
{
q=p;
if(*q==' ')
{
while(*q != '\0')
{
*q = *(q+1);
q++;
}
}
}
printf("%s\n",b);
return 0;
}
void main()
{
// char str[50];
// fflush();
printf("please input a string\n");
gets(str);
printf("after delete space:\n");
delete_space(str);
printf("please input a string 2:\n");
gets(str_2);
printf("after delete space_str_2:\n");
delete_space_by_printor(str_2);
}
0 0
- 4.30 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格
- 删除字符串中的空格(java)
- PB删除字符串中的空格
- C#删除字符串中的空格
- 139.删除字符串中的空格
- 删除字符串中的空格字符
- PHP 删除字符串中的空格
- 大型分布式网站的架构演进
- dos黑框的一些命令
- BIEE-5、回写
- 例题6-3 UVa
- 童玮亮:创业者请铭记这3个关键点,也许下一个成功的将是你
- 4.30 删除字符串中的空格
- 线程池知识点解析
- Struts(1)Struts概念和原理
- 2016-2017学年第二学期C++第五章(1)
- 数据库必会知识点
- Java常用类之String类练习
- 测试0430
- ModelMap和ModelAndView的作用
- C# 读取文件夹下文件,按照名字排序