如题所述
#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;
}
#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 ulbody #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;
}
#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;
}