c语言程序设计问题 输入一个字符串,删除字符串中的所有空格后,输出字符串。(用指针方法解决) 请问

如题所述

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define maxLength 1024 
int main(void)
{
 char *inputChar=(char *)malloc(maxLength*sizeof(char)),*copy=(char *)malloc(maxLength*sizeof(char));
 int length;
 gets(inputChar);
 length=strlen(inputChar);
 for(int j=0,i=0;j<=length;j++)
  if(*(inputChar+j)!=' ')
   *(copy+i++)=*(inputChar+j);
 free(inputChar);
 puts(copy);
 free(copy);
 return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-07-28
body #wrapper, body #head, #head #head_wrapper, body #s_fm, body #s_form_wrapper, body #form, body #wrapper_wrapper, body #u, body #s_tab, body #result_logo img, #u div, #u div a, #head .bdsug ul

body #wrapper, body #head, #head #head_wrapper, body #s_fm, body #s_form_wrapper, body #form, body #wrapper_wrapper, body #u, body #s_tab, body #result_logo img, #u div, #u div a, #head .bdsug ul

第2个回答  2017-07-28
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
char s[500];
int i,j,k;
printf("Please enter a string...\n");
gets(s);
for(j=i=0;s[i];i++)
if(s[i]!=' ')
s[j++]=s[i];
s[j]='\0';
printf("\nThe final result is:\n%s\n",s);
return 0;
}

相关了解……

你可能感兴趣的内容

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