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

2025-02-06 02:40:33
推荐回答(1个)
回答1:

看下面的代码就明白了:

//#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;
}