C语言:输入一个字符串放入数组里,删除其中的空格

尽量别写太长,简单点,我是新手。

程序:
#include <stdio.h>
#include<string.h>
#define N 100
void main()
{
int i=0,j;
char c,str[N];
printf("输入字符串str:\n");
while((c=getchar())!='\n')
{
str[i]=c;//输入字符串
i++;
}
str[i]='\0';
for(i=0;str[i]!='\0';i++)
{
if(str[i]==' ')
{
for(j=i+1;str[j]!='\0';j++)
{
str[j-1]=str[j];
}
str[j]='\0';
}
else continue;
}
str[i-2]='\0';
printf("去掉空格后的字符串为:\n");
for(i=0;str[i]!='\0';i++)
printf("%c",str[i]);
printf("\n");
}
运行结果:
输入字符串str:
ing ing ing
去掉空格后的字符串为:
inginging
Press any key to continue
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-13
#include<stdio.h>
void main()
{char a[8],p;
int i,j;
gets(a);
i=0;j=7
for(;i<j;i++,j--)
{p=a[i];
a[i]=a[j];
a[j]=p;}
puts(a);
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网